[repo-assist] perf: reuse singleton JavaScriptMetricsAnalyzer instance in analyzeFile() - #578
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…le() Sibling analyzers (typescriptAnalyzer.ts, tsxAnalyzer.ts) already reuse a module-level singleton in analyzeFile() to avoid allocating a new analyzer object on every call. javascriptAnalyzer.ts was missed in that earlier pass and still allocated a fresh instance per call. This aligns it with the already-proven pattern used by its siblings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-actions Bot
added a commit
that referenced
this pull request
Aug 28, 2026
…alyzeFile() Applies the same module-level singleton pattern already used by the JS/TS/TSX analyzers (see #578) to the remaining five language analyzers. Each previously allocated a new analyzer instance on every analyzeFile() call; since analyzeFunctions() resets all mutable state (nesting, complexity, details) at the start of each top-level function analysis, reusing one instance per language is safe and avoids unnecessary allocations on every file analyzed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Aug 28, 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
Both sibling analyzers,
typescriptAnalyzer.tsandtsxAnalyzer.ts, already reuse a module-level singleton instance in theiranalyzeFile()static factory to avoid allocating a new analyzer object (and its underlying Tree-sitter parser wiring) on every call — this was called out explicitly in code comments as a deliberate optimization.javascriptAnalyzer.tswas missed when that pattern was introduced and still didreturn new JavaScriptMetricsAnalyzer().analyzeFunctions(sourceText);on every invocation.This PR applies the identical, already-proven singleton pattern to
javascriptAnalyzer.tsfor consistency, eliminating an unnecessary object allocation on everyprovideCodeLensescall for JavaScript files.Why it is safe
JsLikeMetricsAnalyzer(the shared base class) resets its mutable per-analysis state at the start of each top-level function analysis using a save/restore pattern, so reusing a singleton instance across calls is safe — exactly the same reasoning already documented and relied upon bytypescriptAnalyzer.ts/tsxAnalyzer.ts.Trade-offs
None identified. This is a pure internal refactor with no behavioral or API changes.
Test Status
npm run compile: passesnpm run lint: passesnpm run test:unit: 236 tests passing, coverage 98.71/94.99/99.1/98.71 (thresholds 95/88/97/95)npm test(vscode-test): not run in this sandbox (no network access to download the VS Code test binary) — expected/known limitation; CI has network access and will verify.Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.
Add this agentic workflow to your repo
To install this agentic workflow, run