Repository navigation
Conversation
Use tuple stack entries and create edit lists only when a node changes. Reuse array state and skip action checks for callbacks returning None. Keep callback order, callback arguments, and immutable edits unchanged. The native GitHub-schema visitor benchmark drops from 25.01 ms to 14.75 ms. All 3,610 native tests pass, with 18 skipped. Co-Authored-By: Aiden <aiden@weco.ai>
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.
TL;DR
visitwhen walking a GraphQL AST.PYTHONPATH=src python -m pytest tests -qpassed 3,610 tests; 18 skipped.Refs #292
What & Why
Each traversal created named stack entries and empty edit lists, even when visitors made no changes.
It also repeated type checks and checked action values after callbacks returned
None.Use plain tuples for stack entries and create edit lists only when a visitor changes a node.
Reuse saved array state and keep action checks inside the branch for non-
Noneresults.The callback order, callback arguments, and immutable edit rules stay the same.
Validation
These are median times from the repository benchmarks on CPython 3.12.13, Linux x86-64, and an AMD EPYC 9R14.
Both versions ran sequentially on the same isolated benchmark slot, with at least 50 rounds per case.
Pickle decoding does not call
visit; its 0.2% difference is within measurement variation and shows no measured slowdown.The parallel case spends most of its time calling the 25 visitors, so the traversal change helps less.
Run these commands on the base commit and this change:
The complete native suite passed: 3,610 passed, 18 skipped. Ruff and mypy passed for the changed module.
Tests used pytest 9.0.2 and pytest-benchmark 5.3.0; the installed pytest version had a benchmark-plugin setup error on both versions.
Why this is safe and easy to maintain
The change stays inside
visitand uses ordinary tuple unpacking and conditional list creation.It keeps the existing traversal loop, so the change remains small and easy to read.
Output and callback behavior stay unchanged, including replacements, removals, skips, and early stops.
The existing tests in
tests/language/test_visitor.pycover traversal order, paths, ancestors, edits, and parallel visitors.Scope
This changes Python traversal bookkeeping only, with no API changes or new dependencies.
The GraphQL.js traversal order and immutable edit behavior remain unchanged.
AI assistance
Codex gpt-6.1-sol generated candidates tracked with Weco Observe.
Codex also helped select the candidate, run automated checks, and prepare this description.
Weco share link: https://dashboard.weco.ai/share/Fg0y4rbDatKHfqBUeKkfsdtT1nwbnT1k