Skip to content

Index attribute references by name in ModuleNodeIndex - #362

Merged
trissim merged 1 commit into
mainfrom
claude/nra-engine-gaps-0kjz79
Nov 11, 2026
Merged

trissim merged 1 commit into
mainfrom
claude/nra-engine-gaps-0kjz79

Conversation

@trissim

@trissim trissim commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Summary

AnsweredMethod.references() walked every AST node per module per operation — O(total nodes x 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.

What changed

  • module_node_index.py: New attributes_by_attr field — dict[str, tuple[ast.Attribute, ...]] built during the existing BFS walk. Two new match cases collect ast.Attribute nodes by their .attr name.
  • answered_method.py: references() uses index.attributes_by_attr.get(name) for attribute references and index.calls for dynamic access checks. No more ast.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 ModuleNodeIndex is computed once per module per plan and cached as a ParsedModuleFact.

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

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
Copilot AI balanced review requested due to automatic review settings November 11, 2026 19:29
@trissim
trissim merged commit 1832c42 into main Nov 11, 2026
5 of 10 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants