Repository navigation
perf(python): avoid repeated scans of long comment runs - #2866
Closed
doomsday1906 wants to merge 3 commits into
Closed
doomsday1906 wants to merge 3 commits into
doomsday1906 wants to merge 3 commits into
Conversation
doomsday1906
marked this pull request as ready for review
October 23, 2026 21:17
Owner
|
Thanks for speeding up Python files with tens of thousands of comment lines, @doomsday1906! Getting there vendors about 131k lines of grammar, patches its scanner, rebuilds its wasm and changes extraction code every language shares, which is a lot to carry for a rare file shape. Closing this one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Native extraction of a valid Python module with 70,000 leading comments exceeded 90 seconds. The WASM fallback also exceeded a 15-second child deadline on module, function and class shapes.
Two causes combine: indexed child/sibling lookups repeatedly rescan wide extra-node lists, and Python's external scanner repeatedly looks ahead through indented comments. Walk affected children forward, bound backward documentation scans before switching to one forward sibling collection, and locate preceding decorators directly. Preserve documentation order, decorator wrappers, annotation step-over, doc filters, value references and inheritance.
Python's existing v0.23.6 generated parser and headers are copied unchanged from the pinned dependency into the established vendored-grammar build route (MIT license included). Only five scanner lines change. The WASM grammar is now built from those same patched sources; docs/grammars/tree-sitter-python.md records the rebuild command. Generated parser tables account for nearly all of the large diff; no grammar regeneration or version change.
Validation on Linux/WSL at d8e99e9:
Windows x64 and macOS arm64 native builds and native/WASM regressions passed on the exact PR head (237 tests per platform, including the native scaffold). Cross-platform validation. This PR excludes the maintained-fork installer, runtime identity and workstation configuration.