Skip to content

Make a re-map cost less for what did not change, and keep the store from growing - #139

Merged
QuintinBotes merged 3 commits into
mainfrom
goal/88-incremental-remap
Nov 24, 2026
Merged

QuintinBotes merged 3 commits into
mainfrom
goal/88-incremental-remap

Conversation

@QuintinBotes

@QuintinBotes QuintinBotes commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Design

Measured on nopCommerce (pinned in scripts/corpus.json, 24,609 adapter-file pairs, 96 MB of source; cold map, no-change re-map, three committed one-file edits; machine shared, load average about 19, so times are upper bounds). A one-file re-map on main:

  • Time: 10 to 22 s. Every file was a cache hit; the time went to the literals constant-use scan re-reading every source file (0.6 to 3.4 s, 2.6 to 7.2 s in the slowest run), plus per-repository fixed costs: census about 1.4 s, reading all cached facts 0.6 s, linking 0.6 s, hashing every fact in projection 0.6 s, derived facts 0.4 s. A map with nothing changed repeated all of that (9 s).
  • Store: 446 MB after the cold map, of which about 180 MB was the write-ahead log (it counted until the database closed); the database was 263 MB and the blobs 7 MB. Each one-file re-map added 1.75 MB: discover wrote its 1.8 MB result blob under a new digest and never removed the superseded one.
  • The roslyn run in Show progress during map and decompose, and benchmark a real C# monolith #89 (35,502 files, 117,935 cache hits, 0 extracted, 108 s warm against 201 s cold) shows the same shape at scale: with nothing re-extracted, the rest of the pipeline still ran.

Cause. Three things that scale with the repository, not the change: (1) a map with no change re-ran link, discovery and projection; (2) one adapter's whole-repository discover was cached on the blobs of all files it reads, so any edit re-read all of them; (3) caches replaced their blob without deleting the old one, and nothing checkpointed the WAL.

Change.

  1. A skipped map: the key is the commit, the census (path, blob, kind, test flag) of every file, scopes, adapter versions and options, evidence stamp, imported runtime, statistics and delivery data, and the shallow boundary. When it equals the last complete map's key and the stored generation and derived facts are intact, the map returns that map's summary (unchanged: true, 0 re-extracted) after the census. The checkout notice and scope notices are worked out again. A map with failures, or a degraded batch, is never skipped.
  2. literals discover caches, per file in file_index (replaced in place, so no growth), what a scan of that file found, valid for its blob and a digest of the names looked for. A one-file edit rescans one file; a change to the set of constant names rescans all. discover_files in the summary reports scanned and cached.
  3. A replaced discover:* or history:cache blob is deleted when it is still the cache's own (label, no run). PRAGMA wal_checkpoint(TRUNCATE) runs at the end of a map.

Rejected.

  • Incremental linking and a symbol-level dependency index (FR-001 as written): the one-file re-map's remaining cost is about 2.7 s on nopCommerce, spread over five steps, none dominant, so it needs a persisted reverse index per step to go further. A separate change, with its own correctness risk (FR-002); the equality test below guards it.
  • A compact edge encoding (FR-003) and VACUUM: the store is 255 MB for 96 MB of source here (2.7 times), inside SC-002's 3 times, and VACUUM gained nothing (the freelist was 0).
  • Pruning file_index rows of deleted files: scoped maps would delete rows outside their scope.
  • A new table for the per-file discover cache: a migration and an upgrade-test change for no benefit; file_index already has the right key. graphPair now skips these rows (adapter ending :uses).

Summary

Makes an unchanged re-map cost the census, a one-file re-map no longer rescans every file for constant uses, and the store stops growing with each re-map. It meets scenarios 3, 4 and 5; scenarios 1 and 2 are only partly met (see the map).

Refs #88 (first part; incremental linking, compact edges and the benchmark gate follow in a second PR)

Scenario map

Scenario Evidence
1. No-change re-map at most 10% of cold nopCommerce 1.9 s against a cold map of 16.5 s (11.6%; the census alone is 1.4 to 1.8 s). Not gated at 50k: the 50k tier was not re-run
2. 10 changed at most twice no-change one changed file: 4.3 to 4.8 s against 1.9 s (2.3 to 2.5 times). Not met: linking, projection hashing and derived facts still scale with the repository
3. Identical to a cold map tests/unit/graph/delta.test.mjs (existing, passes), remap-cost.test.mjs "a one-file edit rescans one file ... equals a cold map"; nopCommerce after three edits: fact and edge digest of the incremental store equals that of a cold map
4. Store at most 3 times the tree nopCommerce 255 MB for 96 MB of source (2.7 times), was 446 MB (4.6 times)
5. Previous release's store migrates No schema change; old stores have no map:last and map in full once. The upgrade test is in the full run
Requirement Evidence
FR-001 incremental linking Partly: discovery is incremental, linking is not
FR-002 same graph as cold as scenario 3
FR-003 compact edges Not done (see Rejected)
FR-004 benchmark gates the ratios Not done: scripts/bench.mjs is unchanged

Testing steps

Tests (new, each failed before the change), in tests/unit/graph/remap-cost.test.mjs:

  • an unchanged tree re-links, rediscovers and projects nothing (adapter call counts, unchanged, same generation and counts), and a changed file does the full work again;
  • a one-file edit rescans one file (discover_files), a new use is seen, and the stored uses equal a cold map of the final tree;
  • three re-maps with a moving discover result keep one discovery blob and a WAL of 0 frames.

Checks: the full npm test under the lock ran 3,638 tests: 3,627 passed, 9 were not counted as pass or fail (skipped or todo), 2 failed. One is the known requireHumanTTY; the other was semantic.test.mjs (a skipped map did not see a rewritten SCIP index), which this change then fixed by stamping the index files into the skip key (inputs on the scip adapter). Re-run after the fix: the SCIP, remap-cost, delta and mapped-scopes files, 43 of 43 pass. One input outside the census, the scip index, needed this; an adapter that reads other files outside the census must declare them the same way.

Follow-up issues

  • Incremental linking and projection (FR-001, scenario 2) and the 50k bench gate (FR-004).
  • Re-run the 50k and roslyn tiers on an idle machine for the published table.

Review fixes

  • A map in which an enabled SCIP indexer was blocked is not saved as map:last, so installing the tool takes effect on the next map (test: a map with a blocked indexer is not reused once the indexer is installed).
  • casDrop keeps a blob another cache entry still references (test: dropping one adapter's previous blob keeps a blob another adapter still references).
  • Merged origin/main (conflict in docs/benchmarks.md, both sections kept).

Performance & Security & Data Privacy

Performance: as measured above. Security and privacy: the cache blobs deleted are the cache's own (label and no run), the skipped-map summary is the one already stored in the project's own store, and nothing leaves the machine. The measurements are of public repositories only.

Feature flag

None. No behaviour change in the graph (equal to a cold map); unchanged and discover_files are added summary fields.

🤖 Generated with Claude Code

QuintinBotes and others added 3 commits November 24, 2026 09:55
…rom growing

A map whose inputs are all unchanged returns the last complete result after the census. The constant-use scan of the literals adapter reads only files whose content changed. A replaced discovery or history cache blob is deleted, and the write-ahead log is folded into the database after each map.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… drop (#88)

A run:true SCIP language that was missing, timed out or failed fell back to lexical facts but map:last was saved, so the next map returned the lexical result after the tool was installed. Such a map is no longer saved. casDrop now keeps a blob another cache entry still references. The progress test changes a file first, since an unchanged tree is now answered without work.

Refs #88

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant