perf(python): climb the walk cursor for scope-directive and default checks - #2419
Open
Fieldnote-Echo wants to merge 2 commits into
Open
Fieldnote-Echo wants to merge 2 commits into
Fieldnote-Echo wants to merge 2 commits into
Conversation
…hecks For nearly every Python identifier, lexical_ancestor_kind and python_default_value_reference climbed toward the root with ts_node_parent, which re-descends from the root on every step, so a deep expression was cubic. In error-free trees, climb the walk's occurrence cursor instead and take a single parent step for global/nonlocal names, which the grammar makes direct children; trees with errors keep the original climb. sympy's polys/numberfields/resolvent_lookup.py drops from about 8.7 s to 54 ms in the definitions pass, ordinary Python extraction is about 25% faster, and the graph is byte-identical. Signed-off-by: Nelson Spence <nelson@projectnavi.ai>
|
Thanks for opening this — it has been seen, and it is queued. This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence. Current review status: working through a backlog. What that means for this PR, concretely:
Things that will genuinely speed it up whenever review does happen:
If this fixes a bug, a reproduction we can run is worth more than a description of the symptom. Thanks for contributing, and sorry in advance for the wait. |
This branch has not been deployed
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.
Fixes #2417
What does this PR do?
For nearly every Python identifier, usage extraction climbs toward the root with
ts_node_parent, looking for aglobal/nonlocalancestor (lexical_ancestor_kind,internal/cbm/extract_usages.c:1883) and for a parameter default (python_default_value_reference,:1782). Eachts_node_parentcall descends from the root again, so an expression N terms deep costs O(N³). On error-free trees the climbs now follow the walk's occurrence cursor (O(1) per hop, as #2352 did for ReScript). Forglobal/nonlocalone parent step is enough, because the grammar makes those names direct children of the statement. Trees with errors keep today's climb. The graph is byte-identical on 8 corpora, error-recovery trees included.r = c0*x + …, N = 1000 / 2000resolvent_lookup.pyaloneparallel_extractmedian, 823 / 2063 ordinary.pyfilesextract_python_deep_default_parent_climbs_are_linearcounts root-descending parent steps at 200 and 400 terms: 0 here, 62,544 and 245,044 on main with the same counter wired in. Unmodified main passes it, because its climbs do not report to the counter.repro_python_scope_directives_bind_the_named_scopecovers theglobal/nonlocalbinding.Checklist
git commit -s) — required, CI rejectsunsigned commits (DCO, see CONTRIBUTING.md)
make -f Makefile.cbm test)(run as
make -f Makefile.cbm test-par)make -f Makefile.cbm lint-ci)(lint-ci stops at cppcheck with the same findings as on main, none in files touched here; lint-format, lint-no-suppress and lint-memory-core pass)
Prepared with AI assistance (exploration, reproduction, verification, implementation); the spec and design decisions are mine, and I reviewed and ran everything above.