perf: avoid substring allocation in getBinaryOperator for C# && and || - #480
Merged
askpt merged 2 commits intoJul 27, 2026
Merged
Conversation
In tree-sitter-c-sharp, anonymous operator tokens such as && and || use their literal text as the node type. Reading node.type directly avoids a sourceText.substring() heap allocation on every binary logical expression. The previously matched 'binary_operator' case was dead code (no such token type is emitted by the grammar). 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 #480 +/- ##
==========================================
- Coverage 81.43% 81.43% -0.01%
==========================================
Files 13 13
Lines 4347 4346 -1
Branches 439 439
==========================================
- Hits 3540 3539 -1
Misses 806 806
Partials 1 1 ☔ 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 the C# cognitive complexity analyzer by avoiding per-node string allocations when detecting logical && / || operators in binary_expression nodes, improving performance during repeated real-time analysis runs.
Changes:
- Update
getBinaryOperator()in the C# analyzer to returnoperatorNode.typedirectly for&&and||rather than allocating a substring. - Remove the unused
"binary_operator"handling branch based on tree-sitter-c-sharp’s operator token typing behavior. - Expand inline documentation clarifying why
.typeis sufficient for these operators.
askpt
approved these changes
Jul 27, 2026
askpt
deleted the
repo-assist/perf-csharp-binop-O1-20260727-9f87dadefc0d0118
branch
July 27, 2026 11:48
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
In tree-sitter-c-sharp, anonymous operator tokens (
&&,||,+, etc.) use their literal text as the node type — i.e.node.type === "&&". This means we can returnnode.typedirectly instead of allocating a substring viasourceText.substring(startIndex, endIndex).Changes
getBinaryOperator()incsharpAnalyzer.tsBefore:
After:
This eliminates a string allocation on every
&&/||binary expression in C# files. The"binary_operator"branch was dead code — tree-sitter-c-sharp never emits a node of that type; all operators have their literal text as their type.Why this matters
The
getBinaryOperator()method is called for everybinary_expressionnode during analysis. On large C# files with many boolean conditions, this adds up. Avoiding the substring allocation reduces GC pressure during real-time CodeLens analysis.Test Status
npm run compile— clean (0 errors)npm run lint— clean (0 warnings)npm run test:unit— 199/199 passingWarning
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 workflow to your repo
To install this agentic workflow, run