Repository navigation
Index attribute references by name in ModuleNodeIndex - #362
Merged
Merged
Conversation
references() walked every AST node per module per operation — O(total nodes × ops). Now ModuleNodeIndex.attributes_by_attr maps each .attr name to its ast.Attribute nodes, built once in the existing single walk. references() does a dict lookup instead of ast.walk. The dynamic access check also uses the indexed calls list instead of a full walk. On 842 modules, this turns a 14-op batch from 14 × O(nodes) walks into 14 × O(1) lookups on the same cached index. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RnH6dR7JdknxC8XJJtW8Uh
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
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.
Summary
AnsweredMethod.references()walked every AST node per module per operation — O(total nodes x ops). NowModuleNodeIndex.attributes_by_attrmaps each.attrname to itsast.Attributenodes, built once in the existing single walk.references()does a dict lookup instead ofast.walk. The dynamic access check also uses the indexedcallslist.What changed
attributes_by_attrfield —dict[str, tuple[ast.Attribute, ...]]built during the existing BFS walk. Two new match cases collectast.Attributenodes by their.attrname.references()usesindex.attributes_by_attr.get(name)for attribute references andindex.callsfor dynamic access checks. No moreast.walk.Performance impact
On 842 modules, a 14-op flatten_tuple_return batch goes from 14 × O(nodes) full walks to 14 × O(1) lookups on the same cached index. The
ModuleNodeIndexis computed once per module per plan and cached as aParsedModuleFact.Evidence
7/7 tests pass (5.89s vs 6.56s before — the test suite is small; the real win is on 842-module scans).
Generated by Claude Code