-
Notifications
You must be signed in to change notification settings - Fork 8
perf: reduce query latency regression from 3.1.4 to 3.3.0 #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
50ec4a0
1468ef1
7491363
1f9e2e5
55a9f36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,12 +130,19 @@ export const DEFAULTS = { | |
| }, | ||
| }; | ||
|
|
||
| // Per-cwd config cache — avoids re-reading the config file on every query call. | ||
| // The config file rarely changes within a single process lifetime. | ||
| const _configCache = new Map(); | ||
|
|
||
| /** | ||
| * Load project configuration from a .codegraphrc.json or similar file. | ||
| * Returns merged config with defaults. | ||
| * Returns merged config with defaults. Results are cached per cwd. | ||
| */ | ||
| export function loadConfig(cwd) { | ||
| cwd = cwd || process.cwd(); | ||
| const cached = _configCache.get(cwd); | ||
| if (cached) return structuredClone(cached); | ||
|
|
||
| for (const name of CONFIG_FILES) { | ||
| const filePath = path.join(cwd, name); | ||
| if (fs.existsSync(filePath)) { | ||
|
|
@@ -148,13 +155,26 @@ export function loadConfig(cwd) { | |
| merged.query.excludeTests = Boolean(config.excludeTests); | ||
| } | ||
| delete merged.excludeTests; | ||
| return resolveSecrets(applyEnvOverrides(merged)); | ||
| const result = resolveSecrets(applyEnvOverrides(merged)); | ||
| _configCache.set(cwd, structuredClone(result)); | ||
| return result; | ||
| } catch (err) { | ||
| debug(`Failed to parse config ${filePath}: ${err.message}`); | ||
| } | ||
| } | ||
| } | ||
| return resolveSecrets(applyEnvOverrides({ ...DEFAULTS })); | ||
| const defaults = resolveSecrets(applyEnvOverrides({ ...DEFAULTS })); | ||
| _configCache.set(cwd, structuredClone(defaults)); | ||
| return defaults; | ||
| } | ||
|
|
||
| /** | ||
| * Clear the config cache. Intended for long-running processes that need to | ||
| * pick up on-disk config changes, and for test isolation when tests share | ||
| * the same cwd. | ||
| */ | ||
| export function clearConfigCache() { | ||
| _configCache.clear(); | ||
| } | ||
|
Comment on lines
+176
to
178
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The PR description says this is exported "for test use," but a search across the whole codebase shows it is defined here and not imported or called anywhere — including in An unused export is harmless, but it can mislead future contributors into thinking tests or callers rely on it. If the intent is to provide a safety valve for long-running processes that detect config-file changes on disk, a brief inline comment explaining that use case (or a corresponding test) would clarify the intent.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed — updated the JSDoc to clarify the intended use cases: long-running processes that need to detect on-disk config changes, and test isolation when tests share the same cwd. |
||
|
|
||
| const ENV_LLM_MAP = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
structuredCloneguard was applied to cache hits (line 144), but both cache-miss return paths hand the caller the exact same object that was just written into_configCache. A caller mutating the returned config on first use will corrupt every subsequent cache hit from thatcwd.The fix from the previous thread — "loadConfig() now returns
structuredClone(cached)on cache hits" — is incomplete; the same protection needs to apply at initial population. Either store a clone in the cache and return the original, or return a clone at the end of each miss path:And the defaults path needs the same treatment:
Without this, the invariant that "the cache stores a pristine copy that no external caller can touch" only holds after the second call to
loadConfig(cwd), not the first.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed — both cache-miss paths now store structuredClone(result) in the cache and return the original object, ensuring callers can never mutate the cached copy.