Skip to content

fix(cache): Correct key collisions, anchor/whole-file isolation, and cache-hit detection for undefined values#22

Draft
Copilot wants to merge 2 commits intoperf/file-cachefrom
copilot/sub-pr-20
Draft

fix(cache): Correct key collisions, anchor/whole-file isolation, and cache-hit detection for undefined values#22
Copilot wants to merge 2 commits intoperf/file-cachefrom
copilot/sub-pr-20

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 15, 2026

FileCache had three correctness bugs: |-separator key collisions, anchor-scoped parsed results polluting the whole-file cache slot, and false cache misses for legitimately-undefined parsed values (e.g. !ignore-rooted documents).

src/cache.ts

  • Key collision: Replaced flat Map<string, CacheEntry> keyed by "filePath|anchor" with a nested Map<string, Map<string|undefined, unknown>>. Paths or anchors containing | can no longer collide.
  • Anchor/whole-file isolation: Raw file content is now stored in a separate fileContents: Map<string, string>. Calling set(path, content, anchor, fileContent) no longer synthesises a whole-file parsed entry — a subsequent get(path) (no anchor) correctly yields a miss and triggers a fresh full-document parse.
  • has() / hasAsync(): New methods distinguish a stored undefined value from a genuine cache miss, since get() returns undefined in both cases.

src/parser.ts

  • Cache-hit detection now uses cache.has(...) instead of cached !== undefined, so !ignore-rooted files (which parse to undefined) are not endlessly reparsed.
  • cachedContent guard changed from if (cachedContent)if (cachedContent !== undefined) in both sync and async paths, so empty files cached as "" are not re-read from disk.

test/cache.test.ts

  • Updated assertions for set(path, content, anchor, fileContent) — one parsed entry (anchor-scoped), zero whole-file parsed entry, getFileContent still returns the raw string.
  • Added has() assertion to the "cache undefined values" case to cover the new API.

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Co-authored-by: ryodine <5068378+ryodine@users.noreply.github.com>
Copilot AI changed the title [WIP] Add cache to speed up reference resolution fix(cache): Correct key collisions, anchor/whole-file isolation, and cache-hit detection for undefined values Mar 15, 2026
Copilot AI requested a review from ryodine March 15, 2026 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants