Conversation
Previously, the closure returned by createAnalyzer() called require() and validated the analyzer class on every invocation — even though the module is loaded once and the class never changes after that. This commit introduces a per-language cachedAnalyze variable that is populated on the first call and reused for all subsequent calls. After the first successful invocation: - require() is never called again for that language - the class-validity check is skipped - analyzeFile is invoked directly via the cached bound reference The change is purely mechanical (same observable behaviour, same error message on misconfiguration) and makes the resolution lifecycle explicit: lazy init on first use, stable reference thereafter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…lution-20260428-822fe14877b7f5c0
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #275 +/- ##
==========================================
+ Coverage 66.82% 66.96% +0.14%
==========================================
Files 9 9
Lines 2565 2576 +11
Branches 222 224 +2
==========================================
+ Hits 1714 1725 +11
Misses 850 850
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors createAnalyzer() in the VS Code extension’s metrics analyzer factory to lazily resolve and then cache the resolved analyzeFile function per language, avoiding repeated module registry lookups and repeated runtime validation on subsequent analyses.
Changes:
- Cache a bound
analyzeFilereference within thecreateAnalyzer()closure after the first successful invocation. - Preserve lazy-loading behavior while ensuring the module/class guard runs only once per language.
- Update function documentation to describe the one-time resolution/caching behavior.
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.
Problem
The closure returned by
createAnalyzer()previously calledrequire(modulePath)and re-validated the analyzer class on every invocation:While Node.js caches module loads,
require()still incurs a lookup in the module registry on each call, and the class-validity guard runs on every analysis — even though neither the module nor the class can change after the first successful load.Fix
A
cachedAnalyzevariable is introduced in thecreateAnalyzerclosure scope. It isnulluntil the first call, at which point the module is loaded, the class is validated, and the boundanalyzeFilereference is stored. All subsequent calls skip directly tocachedAnalyze(sourceText):Behaviour
Test Status
npm run compile— no errorsnpm run lint— no warningsnpm test(vscode-test) — requires VS Code download; not available in this sandboxed environment (known infrastructure limitation).Warning
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.