perf: use node.type for O(1) operator detection across Go, Rust, Python, JS/TS analyzers#412
Merged
askpt merged 2 commits intoJun 25, 2026
Conversation
…JS/TS analyzers
Replace sourceText.substring() calls with operatorNode.type for binary
and boolean operator detection across four analyzers. Anonymous tokens
in tree-sitter have their literal text as their .type, so no string
allocation or index arithmetic is needed.
Also:
- Go isRecoverCall: use childForFieldName('function') instead of a
linear children.find() scan (O(1) vs O(n))
- Rust/JS else_clause reason: use firstNamedChild?.type instead of
children.some() scan (O(1) vs O(n))
These paths run on every binary/logical expression in the file being
analysed, so avoiding allocations here has measurable benefit on
large, operator-heavy files.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #412 +/- ##
==========================================
- Coverage 78.18% 78.15% -0.04%
==========================================
Files 13 13
Lines 4167 4161 -6
Branches 470 469 -1
==========================================
- Hits 3258 3252 -6
Misses 906 906
Partials 3 3 ☔ 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 optimizes operator detection in several tree-sitter analyzers by avoiding substring() allocations and using SyntaxNode.type (which is the literal token text for anonymous/keyword tokens), plus a couple of small O(1) AST-access tweaks.
Changes:
- Rust/Python/JS-like/Go: switch binary/boolean operator extraction from
sourceText.substring(...)tooperatorNode.type. - Go: switch
recover()detection from an O(n) child scan tochildForFieldName("function"). - Rust & JS-like: change else-clause “else if” detection to an O(1) check (but this introduces a correctness issue for comments/extras between
elseandif).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/metricsAnalyzer/languages/rustAnalyzer.ts | Uses operatorNode.type for logical operator detection; updates else-clause reason detection (issue: firstNamedChild can be a comment). |
| src/metricsAnalyzer/languages/pythonAnalyzer.ts | Uses operatorNode.type for and/or operator detection. |
| src/metricsAnalyzer/languages/jsLikeAnalyzer.ts | Uses operatorNode.type for `&&/ |
| src/metricsAnalyzer/languages/goAnalyzer.ts | Uses childForFieldName("function") for recover() detection; uses operatorNode.type for `&&/ |
Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
askpt
approved these changes
Jun 25, 2026
This was referenced Jun 24, 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
Replace
sourceText.substring()calls withoperatorNode.typefor binary and boolean operator detection in the Go, Rust, Python, and JS/TS (jsLikeAnalyzer) analyzers. Also apply two additional O(1) micro-optimisations in the Go and Rust/JS analyzers.Why this is faster
In tree-sitter, anonymous tokens (e.g.
&&,||,??,and,or) have their literal text as their.typeproperty. The Java analyzer already uses.typefor the same purpose and has done so correctly since the Java analyzer was introduced. This PR brings the other four analyzers into line.Previously each visit to a
binary_expression/boolean_operator/logical_expressionnode triggered a string allocation viasourceText.substring(operatorNode.startIndex, operatorNode.endIndex). These nodes are among the most common in typical TypeScript/JavaScript/Go/Rust/Python source files.Changes
All four analyzers:
getBinaryOperator/getBooleanOperator/getOperatorGo —
isRecoverCallRust & jsLikeAnalyzer —
else_clausereason detectionTest Status
The Java analyzer has been using
operatorNode.typethroughout — that pattern is already validated by the existing test suite. All 149 unit tests (covering binary operators in Go, Rust, Python, JS, and TS) continue to pass unchanged.Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run