Repository navigation
perf(python): climb the walk cursor for scope-directive and default checks - #2419
Fieldnote-Echo wants to merge 5 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. |
Signed-off-by: Nelson Spence <nelson@projectnavi.ai>
|
Thanks for the cursor-based Python walk improvement and the explicit note about the instrumented baseline. I have read the corpus-equivalence and error-tree limits; this remains pending review, with no new change request from this sweep. |
Brings DeusData#2419 onto main a222715. The merge is clean: since the branch's base 0f52d30, main has not changed python_default_value_reference, lexical_ancestor_kind, usage_lexical_scope_id_for_node, record_lexical_binding or handle_usages, nor the occurrence-cursor helpers the change builds on (reset_occurrence_cursor, occurrence_parent, the slow-parent test counter). The merged tree is main plus exactly this PR's three files (internal/cbm/extract_usages.c +57 -16, tests/repro/repro_lexical_binding_precision.c +54, tests/test_extraction.c +44). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
|
Thank you, @Fieldnote-Echo -- this is a careful, well-measured fix. Climbing the walk's occurrence cursor instead of We pushed one commit to your branch:
What we checked on the merged tree:
Thanks again for the thorough measurements and the clear write-up. |
|
Thank you again for the Python cursor improvement. The October updates record the branch refresh and targeted checks as completed on our side. No further contributor work is requested; sorry for the delay in the remaining follow-up, and I’ll follow up soon. |
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
|
Thanks again, @Fieldnote-Echo. We merged current main into your branch once more: one merge commit on top, your three files untouched, and the merge was clean. The earlier red checks came from a wording change on main's website that tripped a docs consistency check on every test leg. Main has fixed that since, and this refresh brings the fix in. While the checks run, we are also comparing graph quality between main and this branch on Django and the Python standard library, which we now do for every performance change before merging. If you push again, please pull first so the merge commit is kept. |
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)(for this PR's changes: CI's lint job passes on this head, and local cppcheck 2.22 / clang-format 23 add no findings over main)
Prepared with AI assistance (exploration, reproduction, verification, implementation); the spec and design decisions are mine, and I reviewed and ran everything above.