perf: cache the resolved cloakbrowser version instead of re-reading it per status call - #213
Open
rajarshidattapy wants to merge 2 commits into
Open
Conversation
Contributor
🟢 No documentation gap found — medium confidenceThe automated review found no documentation gap in the supplied changes. This review is advisory and does not block merging. |
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.
Description
resolveCloakBrowserVersion()did a module resolution, a synchronous file read, and a JSON parse on every invocation, with no caching — for a value that cannot change while the process is alive.It is called more often than it looks.
status()calls it directly (provider.ts:24), andprofileStatuses()calls it inside the.map()(session-manager.ts:126), so once per profile. A singlestatus()with N active profiles performed N+1 resolve-read-parse cycles, all returning the same string.webcmd doctorand every runtime status poll paid that cost; in the daemon, where status is polled repeatedly, it was repeated synchronous I/O on the event loop.Closes #211
The sentinel
The memo uses a
Symbolsentinel rather than a plainif (cached !== undefined)guard:undefinedis a legitimate result — it is what thecatchreturns whencloakbrowsercannot be resolved. Anundefined-based guard would treat that as "not cached yet" and retry the failing resolve on every single call, preserving the bug precisely in the case where the resolution is most likely to be slow. The sentinel caches the failure too.Scope
Deliberately left alone:
profileStatuses()still calls the function inside its.map(). With the cache that is an O(1) lookup per row, and hoisting it would be an unrelated edit to a function this issue is not about.resolveCloakBrowserVersion, and the tenruntimeVersionoccurrences across the suite are all stubbed fixtures. Trivial to add if that changes.Type of Change
Filed as a bug rather than a refactor: the previous implementation cached this per runtime, and the caching was dropped during the local-cloak refactor. This restores intended behavior.
Checklist
Notes on the checklist:
undefinedwhencloakbrowseris unresolvable — it just stops recomputing it.npx tsc --noEmit. It reportssrc/fetch/client.ts(2,23): Cannot find module 'impit'in my environment —impit@0.14.3is independenciesbut absent from mynode_modules, unrelated to any file here.Adapter Notes
Not applicable — this is runtime internals, no adapter is added or modified.
CliErrorsubclasses instead of rawErrorScreenshots / Output
Full local-cloak suite:
The new test lives in its own file because the cache is module-level and the first call anywhere in the process fills it. The spy is installed after the import — loading the module graph performs file reads of its own, and an earlier version of this test counted those too:
Confirmed the test fails without the fix — stashing the
session-manager.tschange and re-running gives: