Giter Site home page Giter Site logo

Extremelly slow checks about pydocstyle HOT 9 CLOSED

pycqa avatar pycqa commented on July 23, 2024
Extremelly slow checks

from pydocstyle.

Comments (9)

JensRantil avatar JensRantil commented on July 23, 2024

Oh -- I am running Python 2.7.1.

from pydocstyle.

JensRantil avatar JensRantil commented on July 23, 2024

This can be reproduced from command line. Execution took 17 seconds with:

$ ../bin/pep257 rewind/*.py rewind/test/*.py

from pydocstyle.

JensRantil avatar JensRantil commented on July 23, 2024

Oh, and one last thing, if you would like me to publish my current pep257 branch for you to reproduce this, I can do that.

from pydocstyle.

JensRantil avatar JensRantil commented on July 23, 2024

Just looking at the code it seems like parse_methods(...) might be called many times with the same arguments in parse_contexts(...) (and takes account for 17 seconds of execution). Refactoring so that each source is parsed only once and having the results cached, one might decrease the time spent in that function a lot. This could possibly be done by implementing something similar to this or this.

from pydocstyle.

JensRantil avatar JensRantil commented on July 23, 2024

This is what the profiling result looks like after the changes that pull request #12 introduces:

 ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      1    0.002    0.002    6.025    6.025 pep257.py:67(<module>)
      1    0.003    0.003    5.996    5.996 pep257.py:366(main)
  190/6    0.001    0.000    5.991    0.999 pep257.py:130(<lambda>)
    118    0.008    0.000    5.991    0.051 pep257.py:323(check_source)
     96    0.000    0.000    4.988    0.052 pep257.py:242(parse_contexts)
    533    0.180    0.000    4.269    0.008 pep257.py:188(parse_top_level)
   1264    1.169    0.001    3.480    0.003 StringIO.py:168(readlines)
   1040    0.007    0.000    2.894    0.003 pep257.py:137(abs_pos)
     65    0.000    0.000    2.495    0.038 pep257.py:208(parse_classes)
1152457    1.685    0.000    2.222    0.000 StringIO.py:139(readline)
 331865    1.060    0.000    2.033    0.000 tokenize.py:264(generate_tokens)
 314711    0.080    0.000    2.022    0.000 {next}
     78    0.000    0.000    1.774    0.023 pep257.py:204(parse_functions)
     78    0.000    0.000    0.944    0.012 pep257.py:118(cached_func)
    135    0.003    0.000    0.944    0.007 pep257.py:226(parse_methods)
 309500    0.771    0.000    0.771    0.000 {built-in method match}
    112    0.002    0.000    0.707    0.006 pep257.py:278(__init__)
    224    0.060    0.000    0.703    0.003 pep257.py:144(rel_pos)
1152693    0.362    0.000    0.362    0.000 {method 'find' of 'str' objects}
   2108    0.018    0.000    0.200    0.000 pep257.py:172(parse_docstring)

from pydocstyle.

JensRantil avatar JensRantil commented on July 23, 2024

Every file checked generates two calls to parse_functions(...), parse_classes(...) and parse_methods(...) through parse_contexts(...). By caching those results whenever possible a one would be able to gain 2.495/2+1.774/2+ 0.944/2=2.59 seconds more in the example above.

from pydocstyle.

JensRantil avatar JensRantil commented on July 23, 2024

Every file checked generates two calls to parse_functions(...), parse_classes(...) and parse_methods(...) through parse_contexts(...). By caching those results whenever possible a one would be able to gain 2.495/2+1.774/2+ 0.944/2=2.59 seconds more in the example above.

This fix was added in pull request #12.

from pydocstyle.

keleshev avatar keleshev commented on July 23, 2024

#12 is merged now. pep257 is probably still 10 times slower than it could be, but good enough for now.

If you come up with more speed improvements—you are welcome!

from pydocstyle.

JensRantil avatar JensRantil commented on July 23, 2024

#12 is merged now. pep257 is probably still 10 times slower than it could be, but good enough for now.

I agree, but works for now!

If you come up with more speed improvements—you are welcome!

Sure! But for now it doesn't hinder me in running my tests.

from pydocstyle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.