[repo-assist] perf: avoid node.children array allocation in hot AST traversal loops - #554
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
Tree-sitter's node.children getter materializes a new JS array on every access rather than returning a cached property. The main visit()/traversal loops in goAnalyzer, javaAnalyzer, jsLikeAnalyzer (used by JS/TS/TSX), pythonAnalyzer, rustAnalyzer, and two remaining loops in csharpAnalyzer ran this allocation on every single AST node visited during analysis - the hottest path in the extension. csharpAnalyzer.ts already used the childCount/child(i) pattern in most places with a comment explaining why; this change applies the same already-proven, behavior-preserving pattern consistently to the remaining loops across all language analyzers, eliminating one throwaway array allocation per node visited. No behavioral change: iterates the same children in the same order. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
🤖 This is an automated pull request from Repo Assist, an AI assistant. See .github/workflows/repo-assist.md for details.
What
Tree-sitter's
node.childrengetter materializes a new JS array on every access rather than returning a cached property. The mainvisit()/child-iteration loops ingoAnalyzer.ts,javaAnalyzer.ts,jsLikeAnalyzer.ts(shared by JS/TS/TSX),pythonAnalyzer.ts,rustAnalyzer.ts, and two remaining loops incsharpAnalyzer.tsusedfor (const child of node.children). Since thesevisit()functions recurse over every node in the AST, this allocated one throwaway array per node visited across the whole file - the hottest path in the extension.csharpAnalyzer.tsalready applied the fix (with an explanatory comment) to most of its own loops; this PR extends the same already-proven pattern consistently to the remaining loops in that file and to all the other language analyzers:Why this is safe
csharpAnalyzer.tsaround thechildCount/child(i)usage).Test Status
npm run compile: cleannpm run lint: cleannpm run test:unit(mocha + c8 coverage): 225 passing, coverage unchanged (83.84% stmts / 93.66% branch / 96.19% funcs / 83.84% lines - matches baseline, no regression)npm test(full vscode-test suite): not run - blocked by sandbox network restrictions (VS Code download), as documented in repo instructions; this is expected in this environment.Closes no issue - proactive Task 8 (Performance Improvements) engineering-quality PR.
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.
Add this agentic workflow to your repo
To install this agentic workflow, run