Skip to content

[repo-assist] perf: hoist regex literals in C# ERROR-node heuristics to module scope - #555

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/improve-hoist-csharp-error-node-regex-20260820-e7b1f41608bdada5
Draft

[repo-assist] perf: hoist regex literals in C# ERROR-node heuristics to module scope#555
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/improve-hoist-csharp-error-node-regex-20260820-e7b1f41608bdada5

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant. See .github/workflows/repo-assist.md for details.

What

The C# preprocessor ERROR-node/malformed-declaration complexity heuristics (getComplexityFromErrorNode, getComplexityFromMalformedDeclaration, and their *Reason counterparts in csharpAnalyzer.ts) used inline regex literals that get recompiled on every call. These heuristics run whenever tree-sitter cannot parse a method body cleanly due to preprocessor directives (#if/#else), which can happen multiple times per file in preprocessor-heavy C# code.

This PR hoists all of those regex literals to module-level const declarations (e.g. IF_KEYWORD_REGEX, LOGICAL_OPERATOR_GLOBAL_REGEX, TERNARY_OPERATOR_REGEX), avoiding repeated regex compilation on each invocation - the same "hoist to module scope" pattern already used elsewhere in this codebase (see codeLensProvider.ts's excludeRegexCache).

Why this is safe

  • Identical patterns, same test order and short-circuiting logic - purely a compile-once vs compile-per-call change.
  • No output/behavior change, confirmed by the full unit test suite (including the dedicated CSharp preprocessor ERROR node reason branches and malformed declaration fallback tests) passing unchanged.

Test Status

  • npm run compile: clean
  • npm run lint: clean
  • npm run test:unit (mocha + c8 coverage): 225 passing, coverage unchanged (83.83% stmts / 93.66% branch / 96.19% funcs / 83.83% lines vs baseline 83.84% - negligible, no regression; the tiny stmt-count shift is purely due to added const declarations, not reduced coverage)
  • npm test (full vscode-test suite): not run - blocked by sandbox network restrictions (VS Code download), as documented in repo instructions; expected in this environment.

Proactive Task 5 (Coding Improvements) PR, complementing the companion perf PR for node.children allocation avoidance from the same run.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by 🌈 Repo Assist, see workflow run. Learn more.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@42c2ab5b4e4c9273534c39259b2e0df7f20f07e9

The ERROR-node and malformed-declaration complexity heuristics in
csharpAnalyzer.ts (getComplexityFromErrorNode, getComplexityFromMalformedDeclaration,
and their corresponding *Reason variants) used inline regex literals that were
recompiled on every invocation. These heuristics can run multiple times per file
when preprocessor directives split method bodies across ERROR nodes.

Hoisted all regex literals used by these functions to module-level const
declarations, matching the "hoist to module scope" pattern already used
elsewhere in the codebase (e.g. codeLensProvider.ts's excludeRegexCache).

No behavioral change: same patterns, same test order/short-circuiting.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants