perf: use O(1) positional child access for binary operator lookup#394
Merged
askpt merged 2 commits intoJun 21, 2026
Merged
Conversation
Replace O(n) node.children iteration with O(1) node.child(1) access in all language analyzers for getBinaryOperator / getBooleanOperator / getOperator methods. In every tree-sitter grammar (C#, Go, Java, JS/TS, Python, Rust), a binary_expression (or boolean_operator) has exactly three children: [left, operator, right]. The operator is always at index 1. Using node.child(1) avoids allocating the children array and iterating up to three elements for every logical operator encountered during analysis, which improves performance on deeply nested or complex expressions. Files changed: csharpAnalyzer.ts, goAnalyzer.ts, javaAnalyzer.ts, jsLikeAnalyzer.ts, pythonAnalyzer.ts, rustAnalyzer.ts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…621-842fbf1d80b798a4
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #394 +/- ##
==========================================
- Coverage 76.26% 76.17% -0.09%
==========================================
Files 13 13
Lines 4086 4088 +2
Branches 447 445 -2
==========================================
- Hits 3116 3114 -2
- Misses 968 972 +4
Partials 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves performance in the Tree-sitter language analyzers by replacing O(n) scans of node.children (which allocates an array) with O(1) positional access via node.child(1) when extracting logical/binary operators.
Changes:
- Updated operator-extraction helpers to use
node.child(1)instead of iteratingnode.children. - Preserved existing safety behavior by returning
nullwhen the operator node is missing or not one of the expected operators. - Applied consistently across the Rust, Python, JS-like, Java, Go, and C# analyzers.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/metricsAnalyzer/languages/rustAnalyzer.ts | Use positional child access to fetch &&/` |
| src/metricsAnalyzer/languages/pythonAnalyzer.ts | Use positional child access to fetch and/or in boolean_operator. |
| src/metricsAnalyzer/languages/jsLikeAnalyzer.ts | Use positional child access to fetch &&/` |
| src/metricsAnalyzer/languages/javaAnalyzer.ts | Use positional child access to fetch &&/` |
| src/metricsAnalyzer/languages/goAnalyzer.ts | Use positional child access to fetch &&/` |
| src/metricsAnalyzer/languages/csharpAnalyzer.ts | Use positional child access to fetch operator node for binary_expression (including binary_operator). |
This was referenced Jun 21, 2026
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 PR was created by Repo Assist, an automated AI assistant.
Summary
Replaces O(n)
node.childreniteration with O(1)node.child(1)positional access in all language analyzers for thegetBinaryOperator/getBooleanOperator/getOperatormethods.Motivation
Every
binary_expression(and Python'sboolean_operator) node in tree-sitter has exactly three children:The previous code iterated
node.children— a JS Array that tree-sitter allocates on every access — and used.find()or afor...ofloop to locate the operator. Since the operator is always at index 1,node.child(1)is both correct and constant-time.Changes
All six language analyzers are updated:
csharpAnalyzer.tsgetBinaryOperatorgoAnalyzer.tsgetBinaryOperatorjavaAnalyzer.tsgetBinaryOperatorjsLikeAnalyzer.tsgetOperatorpythonAnalyzer.tsgetBooleanOperatorrustAnalyzer.tsgetBinaryOperatorThe operator type/text check is preserved — if
child(1)is unexpectedly missing or is not a logical operator, the method returnsnullsafely, matching existing behaviour.Test Status
All 103 tests pass (
npm run test:unit). Lint clean (npm run lint). No regressions.Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comSee Network Configuration for more information.