Skip to content

perf: replace multi-comparison type chains with static readonly Sets#434

Merged
askpt merged 3 commits into
mainfrom
repo-assist/perf-static-type-sets-20260702-9eaca670bed4cbef
Jul 3, 2026
Merged

perf: replace multi-comparison type chains with static readonly Sets#434
askpt merged 3 commits into
mainfrom
repo-assist/perf-static-type-sets-20260702-9eaca670bed4cbef

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist.

Summary

Replaces multi-step OR-chain type checks in six language analyzers with static readonly Set lookups, improving per-node performance on the analysis hot path.

This pattern was already established by TYPE_DECLARATION_TYPES in CSharpMetricsAnalyzer — this PR extends it consistently to all analyzers.

Changes

Analyzer Sets Added Methods Updated
csharpAnalyzer.ts FUNCTION_DECLARATION_TYPES (7), NESTING_TYPES (9) isFunctionDeclaration, increasesNesting
javaAnalyzer.ts METHOD_DECLARATION_TYPES (2), NESTING_TYPES (8) isMethodDeclaration, increasesNesting
goAnalyzer.ts NESTING_TYPES (6) increasesNesting
jsLikeAnalyzer.ts FUNCTION_NODE_TYPES (4), NESTED_FUNCTION_TYPES (3), NESTING_TYPES (7) isFunctionNode, isNestedFunction, increasesNesting
pythonAnalyzer.ts NESTING_TYPES (9) increasesNesting (replaces switch/case)
rustAnalyzer.ts NESTING_TYPES (6) increasesNesting

No logic changes; all existing tests continue to pass.

Rationale

isFunctionDeclaration, isMethodDeclaration, isNestedFunction, and increasesNesting are called on every AST node during traversal. Converting sequential OR-chain string comparisons to Set.has() reduces per-node overhead on every analysed file — the benefit scales with file size and the number of node types in each chain (up to 9 comparisons replaced by a single hash lookup).

Test Status

npm run compile  ✅ (0 errors)
npm run lint     ✅ (0 warnings)
npx mocha out/unit/unit.test.js  ✅ 159 passing

No new tests needed — no logic changes.

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.

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1c6668b751c51af8571f01204ceffb19362e0f66

Replace long or-chain type checks in six analyzers with static readonly
Sets, consistent with the existing TYPE_DECLARATION_TYPES pattern in
CSharpMetricsAnalyzer.  The affected methods — isFunctionDeclaration,
isMethodDeclaration, isNestedFunction, and increasesNesting — are called
on every node during AST traversal, so converting from O(n) sequential
string comparisons to O(1) Set.has() lookups reduces per-node overhead
on every analysed file.

Changes by file:
- csharpAnalyzer.ts : FUNCTION_DECLARATION_TYPES (7 entries),
  NESTING_TYPES (9 entries)
- javaAnalyzer.ts   : METHOD_DECLARATION_TYPES (2 entries),
  NESTING_TYPES (8 entries)
- goAnalyzer.ts     : NESTING_TYPES (6 entries)
- jsLikeAnalyzer.ts : FUNCTION_NODE_TYPES (4 entries),
  NESTED_FUNCTION_TYPES (3 entries), NESTING_TYPES (7 entries)
- pythonAnalyzer.ts : NESTING_TYPES (9 entries, replaces switch/case)
- rustAnalyzer.ts   : NESTING_TYPES (6 entries)

No logic changes; all 159 unit tests continue to pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@askpt askpt changed the title [repo-assist] perf: replace multi-comparison type chains with static readonly Sets perf: replace multi-comparison type chains with static readonly Sets Jul 3, 2026
@askpt

askpt commented Jul 3, 2026

Copy link
Copy Markdown
Owner

@copilot resolve the merge conflicts in this pull request

…ith Set lookups

Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>

Copilot AI commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in 62c3dd1. The conflict was in jsLikeAnalyzer.ts where main added generator function support (generator_function_declaration / generator_function) at the same time our PR replaced OR-chains with Set lookups.

Resolution: kept the Set-based approach and added the new generator types to both FUNCTION_NODE_TYPES and NESTED_FUNCTION_TYPES. The auto-merged getFunctionReason and getFunctionName updates from main were also incorporated. All 165 tests pass (npm run compile ✅, npm run lint ✅, 165 passing ✅).

Copilot finished work on behalf of askpt July 3, 2026 17:07
Copilot AI requested a review from askpt July 3, 2026 17:07
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.76%. Comparing base (90a1c37) to head (21a8f87).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #434      +/-   ##
==========================================
+ Coverage   78.62%   78.76%   +0.14%     
==========================================
  Files          13       13              
  Lines        4211     4239      +28     
  Branches      474      418      -56     
==========================================
+ Hits         3311     3339      +28     
  Misses        898      898              
  Partials        2        2              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@askpt askpt marked this pull request as ready for review July 3, 2026 17:21
Copilot AI review requested due to automatic review settings July 3, 2026 17:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the cognitive complexity “hot path” in the language analyzers by replacing repeated string OR-comparisons (and one switch) with static readonly Set membership checks, aligning with the existing TYPE_DECLARATION_TYPES pattern in the C# analyzer.

Changes:

  • Introduced static readonly ReadonlySet<string> constants for frequently-checked node-type groups across analyzers.
  • Updated increasesNesting and function/method identification helpers to use Set.has(node.type) instead of comparison chains.
  • Kept behavior consistent with existing logic while improving per-node traversal overhead.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/metricsAnalyzer/languages/csharpAnalyzer.ts Adds FUNCTION_DECLARATION_TYPES/NESTING_TYPES sets and switches checks to Set.has()
src/metricsAnalyzer/languages/javaAnalyzer.ts Adds method/nesting type sets and replaces OR-chains with Set.has()
src/metricsAnalyzer/languages/goAnalyzer.ts Adds NESTING_TYPES and updates nesting check to Set.has()
src/metricsAnalyzer/languages/jsLikeAnalyzer.ts Adds function/nested-function/nesting sets and replaces OR-chains with Set.has()
src/metricsAnalyzer/languages/pythonAnalyzer.ts Adds NESTING_TYPES and replaces switch-based nesting logic with Set.has()
src/metricsAnalyzer/languages/rustAnalyzer.ts Adds NESTING_TYPES and updates nesting check to Set.has()

Comment thread src/metricsAnalyzer/languages/jsLikeAnalyzer.ts Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@askpt askpt merged commit 5ad9942 into main Jul 3, 2026
9 checks passed
@askpt askpt deleted the repo-assist/perf-static-type-sets-20260702-9eaca670bed4cbef branch July 3, 2026 17:26
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.

3 participants