Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements #48

Merged
merged 9 commits into from
Jun 15, 2022
Merged

Performance improvements #48

merged 9 commits into from
Jun 15, 2022

Conversation

hnesk
Copy link
Owner

@hnesk hnesk commented Jun 15, 2022

Gettting rid of pkg_resources brings a good performance improvement, from 1.178s to 0.864s in startup time on my machine
Contains also some less imports when not TYPE_CHECKING

$ STARTUP_PROFILE=1 browse-ocrd 
         1389599 function calls (1321032 primitive calls) in 1.178 seconds

   Ordered by: internal time
   List reduced from 4716 to 20 due to restriction <20>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
39203/262    0.063    0.000    0.243    0.001 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/pkg_resources/_vendor/pyparsing.py:1370(_parseNoCache)
        1    0.063    0.063    0.130    0.130 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/ocrd_browser/application.py:53(do_activate)
      575    0.051    0.000    0.051    0.000 {built-in method marshal.loads}
       34    0.041    0.001    0.041    0.001 {built-in method _imp.create_dynamic}
        1    0.035    0.035    0.036    0.036 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/ocrd_browser/application.py:26(do_startup)
    20365    0.029    0.000    0.033    0.000 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/pkg_resources/_vendor/pyparsing.py:363(__new__)
      455    0.024    0.000    0.024    0.000 {built-in method builtins.compile}
        1    0.024    0.024    0.052    0.052 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/ocrd_browser/view/page.py:310(build)
1767/1717    0.022    0.000    0.105    0.000 {built-in method builtins.__build_class__}
     5075    0.021    0.000    0.048    0.000 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/version.py:261(__init__)
20365/19896    0.020    0.000    0.030    0.000 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/pkg_resources/_vendor/pyparsing.py:372(__init__)
        1    0.018    0.018    0.018    0.018 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/ocrd_browser/view/base.py:141(__init__)
 1125/220    0.017    0.000    0.046    0.000 /usr/lib/python3.8/sre_parse.py:493(_parse)
     6433    0.017    0.000    0.017    0.000 {built-in method posix.stat}
 4796/652    0.016    0.000    0.211    0.000 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/pkg_resources/_vendor/pyparsing.py:3547(parseImpl)
   156784    0.016    0.000    0.016    0.000 {built-in method builtins.isinstance}
       58    0.015    0.000    0.015    0.000 {method 'get_g_type' of 'gi.RegisteredTypeInfo' objects}
 4864/262    0.013    0.000    0.242    0.001 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/pkg_resources/_vendor/pyparsing.py:3397(parseImpl)
        1    0.013    0.013    0.013    0.013 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/ocrd_browser/util/gtk.py:65(WhenIdle)
     1320    0.011    0.000    0.043    0.000 <frozen importlib._bootstrap_external>:1498(find_spec)




$ STARTUP_PROFILE=1 browse-ocrd 
         791765 function calls (774883 primitive calls) in 0.864 seconds

   Ordered by: internal time
   List reduced from 4653 to 20 due to restriction <20>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      577    0.066    0.000    0.066    0.000 {built-in method marshal.loads}
        1    0.063    0.063    0.127    0.127 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/ocrd_browser/application.py:53(do_activate)
       34    0.047    0.001    0.047    0.001 {built-in method _imp.create_dynamic}
        1    0.037    0.037    0.047    0.047 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/ocrd_browser/application.py:26(do_startup)
      455    0.029    0.000    0.029    0.000 {built-in method builtins.compile}
1778/1727    0.024    0.000    0.095    0.000 {built-in method builtins.__build_class__}
        1    0.021    0.021    0.049    0.049 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/ocrd_browser/view/page.py:310(build)
        1    0.019    0.019    0.019    0.019 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/ocrd_browser/view/base.py:141(__init__)
 1127/219    0.017    0.000    0.046    0.000 /usr/lib/python3.8/sre_parse.py:493(_parse)
     6272    0.016    0.000    0.016    0.000 {built-in method posix.stat}
       57    0.015    0.000    0.015    0.000 {method 'get_g_type' of 'gi.RegisteredTypeInfo' objects}
      577    0.011    0.000    0.011    0.000 {built-in method io.open_code}
     1322    0.011    0.000    0.043    0.000 <frozen importlib._bootstrap_external>:1498(find_spec)
      916    0.010    0.000    0.013    0.000 /usr/lib/python3.8/sre_compile.py:276(_optimize_charset)
     2909    0.010    0.000    0.022    0.000 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/version.py:261(__init__)
        1    0.009    0.009    0.184    0.184 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/gi/overrides/Gio.py:39(run)
 1953/207    0.008    0.000    0.023    0.000 /usr/lib/python3.8/sre_compile.py:71(_compile)
    69525    0.007    0.000    0.008    0.000 {built-in method builtins.isinstance}
        2    0.007    0.003    0.007    0.003 /home/jk/Projekte/ocrd_all_2020/venv/lib/python3.8/site-packages/gi/_gtktemplate.py:175(init_template)
      457    0.006    0.000    0.006    0.000 {built-in method posix.listdir}

@lgtm-com
Copy link

lgtm-com bot commented Jun 15, 2022

This pull request introduces 1 alert when merging 3daa04d into 7430ca1 - view on LGTM.com

new alerts:

  • 1 for Module is imported with 'import' and 'import from'

@lgtm-com
Copy link

lgtm-com bot commented Jun 15, 2022

This pull request introduces 1 alert when merging a02717a into 7430ca1 - view on LGTM.com

new alerts:

  • 1 for Module is imported with 'import' and 'import from'

@lgtm-com
Copy link

lgtm-com bot commented Jun 15, 2022

This pull request fixes 1 alert when merging c17a3b9 into 7430ca1 - view on LGTM.com

fixed alerts:

  • 1 for Unused local variable

@hnesk hnesk merged commit c84e55c into master Jun 15, 2022
@hnesk hnesk deleted the performance branch June 15, 2022 13:36
@kba
Copy link
Contributor

kba commented Jun 15, 2022

That is indeed a signifcant improvement, thanks for sharing (and implementing). We'll investigate to do the same in core and dependent packages, cf OCR-D/core#881

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants