Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
Description
For example,./python -m pydoc test.test_enum
takes 32 seconds. It is 20 seconds in 3.12, 15 seconds in 3.11 and only 1.6 seconds in 3.10. Well, perhapstest.test_enum
was grown, but the main culprit isbpo-35113. And further changes likegh-106727 only added to it.
For every class without a docstringpydoc
tries to find its comments by callinginspect.getcomments()
which callsinspect.findsource()
which reads and parses the module source, then traverse it and find classes with the specific qualname. For large modules with many classes it has quadratic complexity.
I tried to optimize the AST traversing code, and get 18 seconds on main. It still has quadratic complexity. Further optimization will require introducing a cache and finding positions of all classes in one pass.
But it all would be much simpler and faster if simply save the value ofco_firstlineno
of the code object executed during class creation in the file dict (as__firstlineno__
for example).