perf: avoid array allocation in C# operator name lookup and substring in Go recover check - #493
Merged
askpt merged 2 commits intoAug 2, 2026
Conversation
… in Go recover check - csharpAnalyzer: replace node.children.find() with direct node.child(i) iteration in conversion_operator_declaration and identifier fallback paths; node.children creates a new array on each call, while child(i) is an O(1) index lookup with no allocation. - goAnalyzer: add length short-circuit (endIndex - startIndex !== 7) in isRecoverCall before the substring comparison; every call_expression triggers this check, and 99%+ of call sites are not recover() — the length test avoids a string allocation for all of them. 199 tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #493 +/- ##
==========================================
- Coverage 81.39% 81.37% -0.02%
==========================================
Files 13 13
Lines 4353 4366 +13
Branches 441 442 +1
==========================================
+ Hits 3543 3553 +10
- Misses 809 812 +3
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 applies two micro-optimizations in the Go and C# metrics analyzers to reduce allocation overhead while traversing Tree-sitter AST nodes during cognitive complexity analysis.
Changes:
- Go: add a length short-circuit in
isRecoverCallto avoid most substring calls. - C#: replace
node.children.find(...)withnode.child(i)loops to avoidnode.childrenarray materialization.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/metricsAnalyzer/languages/goAnalyzer.ts | Adds a constant-time length guard before extracting the callee identifier text. |
| src/metricsAnalyzer/languages/csharpAnalyzer.ts | Replaces node.children scans with child(i) loops to avoid array allocation in function-name extraction. |
…or implicit/explicit keyword Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
askpt
deleted the
repo-assist/perf-go-csharp-O1-recover-20260802-2ce203bc1a98db42
branch
August 2, 2026 12:56
This was referenced Aug 1, 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 pull request was created by Repo Assist, an automated AI assistant.
Summary
Two targeted micro-optimizations that reduce allocation pressure in the C# and Go analyzers.
1. Go: length short-circuit in
isRecoverCallFile:
src/metricsAnalyzer/languages/goAnalyzer.tsEvery
call_expressionnode in a Go file triggersisRecoverCall. Previously, this always calledsourceText.substring(startIndex, endIndex)— a string allocation — to compare against"recover". Sincerecoveris exactly 7 characters, we can short-circuit with an integer comparison first:In a typical Go file with many function calls, this avoids a string allocation for all non-
recovercall sites.2. C#: replace
node.children.find()with directnode.child(i)accessFile:
src/metricsAnalyzer/languages/csharpAnalyzer.tsnode.childrenin tree-sitter is a getter that materialises a new JavaScript array on every call. Two places ingetFunctionNameusednode.children.find(...), which allocates an array every timegetFunctionNameruns:conversion_operator_declaration: Theimplicit/explicitkeyword appears in the first 4 children (after 0–3 modifier nodes). Replaced with a boundedforloop usingnode.child(i)— no array allocation.node.children.find(child => child.type === "identifier")with aforloop usingnode.child(i), also avoiding the array allocation.Trade-offs
call_expression; this is negligible compared to the allocation saved.conversion_operator_declarationis safe: C# modifiers on conversion operators are at mostpublic,static,new(3 modifiers), soimplicit/explicitis always at index ≤ 3.Test Status
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 workflow to your repo
To install this agentic workflow, run