-
Notifications
You must be signed in to change notification settings - Fork 42
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
Improve performance #149
Improve performance #149
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #149 +/- ##
==========================================
- Coverage 93.49% 93.10% -0.39%
==========================================
Files 4 4
Lines 722 725 +3
==========================================
Hits 675 675
- Misses 47 50 +3 ☔ View full report in Codecov by Sentry. |
Ah, the coverage diff is because the |
Feel free to remove code that is no longer used in the PR. |
This is wonderful! Thank you for improving not only the performance, but also the code quality along the way. Much appreciated! --JK |
The most expensive thing (by far) in all the code is parsing the comments of the class variables, and in particular getting the source code of the classes with
inspect.getsource
andtokenize.generate_tokens
.I noticed 2 bottlenecks about this:
issubclass(Tap, Tap) is True
! This caused both functions to be called forTap
itself, which is quite large and so they had troubleinspect
side anyway, but it will always be better not to count on that. The idea is to replace theobj
parameter in each parsing function into what they really need (the tokens or the source code).Benchmark
Used ipython for the timeit
With a simple class like this:
Before:
After:
Of course, the bigger the class, the slower it will be:
It will always be slower than
argparse.ArgumentParser
:But it's quite close, i don't think it is an issue now.. as long as the class is small. I don't think that's enough to solve #42.