terrencepreilly / darglint

A python documentation linter which checks that the docstring description matches the definition.
MIT License
481 stars 41 forks source link

Use mypyc for cyk.py #193

Closed twoertwein closed 2 years ago

twoertwein commented 2 years ago

This PR uses mypyc to compile cyk.py to a python c-extension. It would be beneficial to also compile all files that cyk.py imports.

To test the compiled version simply replace darglint = ... in pyproject with darglint = {git = "https://github.com/twoertwein/darglint"}.

Compiling cyk.py improves the speed for the numpy and google style. Using the example from @webknjaz in #186:

wget https://raw.githubusercontent.com/ansible/ansible-navigator/295b1529f461dd3dc69d4271a909ad7ea9a9cac1/src/ansible_navigator/runner/base.py
for style in sphinx numpy google; do echo Checking $style docstrings...; time darglint -s $style base.py &>/dev/null; done

official darglint 1.8.1

Checking sphinx docstrings...

real    0m0.242s
user    0m0.211s
sys     0m0.032s
Checking numpy docstrings...

real    9m19.110s
user    9m18.890s
sys     0m0.213s
Checking google docstrings...

real    10m33.168s
user    10m32.860s
sys     0m0.276s

with this PR and mypy 0.931

Checking sphinx docstrings...

real    0m0.245s
user    0m0.217s
sys     0m0.028s
Checking numpy docstrings...

real    2m30.529s
user    2m30.296s
sys     0m0.232s
Checking google docstrings...

real    2m53.705s
user    2m53.473s
sys     0m0.232s
webknjaz commented 2 years ago

This seems to be a band-aid rather than a solution. And it's still unacceptably slow. 2.5-3 min per Python module in a project with more than one module would be already 6 minutes.

P.S. This change would turn darglint into a dist requiring a whole matrix of platform-specific wheels to be shipped, which would need much more effort than this small patch, which is already failing in the CI.

twoertwein commented 2 years ago

Fully agree with all your points :) and on other files it is exactly as slow as before