Skip to content

Read only new commits on a re-map, keep clone fingerprints out of the graph, and gate the #88 ratios - #140

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

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

Conversation

@QuintinBotes

@QuintinBotes QuintinBotes commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Design

Profile. One-file edit on nopCommerce (pinned, 6,741 files, 24,609 adapter-file pairs), committed, then re-mapped with --cpu-prof, on main after #139: 4.2 s wall against 1.7 s for a no-change re-map (2.5 times). Phases: census 1.2 s (the floor every map pays: one open per file for its first bytes, 0.63 s), extraction 0.66 s (reading every cached fact, 0.15 s of it JSON.parse; 0.2 s matching each adapter's globs against every path), link 0.79 s (generic 0.33, quality 0.16, scip 0.05, the rest small), history 0.41 s (git log --numstat over the whole window again because the commit changed), projection 0.56 s (hashing every fact, 0.21 s in factId), derived 0.39 s (Graph.fromStore 0.31 s). No step dominates; each is proportional to the repository.

Cause. After a change every step past the census runs over the whole repository. Two of them do work that cannot have changed: history re-reads the numstat of every commit in the window although only the new commit is new, and the graph carries the quality adapter's clone fingerprints (11 MB of fact attrs and 12.6 MB of node attrs on nopCommerce) that only its link reads, so projection hashes them, the store writes them and Graph.fromStore parses them on every map.

Chosen change.

  1. History reads only commits it has not seen. It lists the window with git log --no-merges --format=%H and the same --since / -n arguments as before, so the commit set and order are exactly those of a full read, then reads --numstat for unseen shas with --no-walk=unsorted --stdin. Commits are immutable, so their parsed changes are kept by sha in one CAS blob (history:commits, without the author hash, pruned to the window, replaced and the old blob dropped). history.commits_read in the summary says how many were read.
  2. quality deletes the fingerprints from the facts after its link has used them. The per-file cache keeps them, so the next link still has them; the graph keeps attrs.clones. Nothing else reads them (searched). FAST_VERSION is bumped so a stored skip-key does not return the old graph; the first map after upgrade rewrites those module facts once.
  3. Each adapter's file globs are compiled once per map (matcher in core/glob.mjs), not looked up per path.
  4. FR-004: scripts/bench.mjs records tree_bytes and the three Make a re-map cost proportional to the change, with a compact store #88 ratios with explicit bounds (GATES: no change / cold <= 0.1, changed / no change <= 2, store / tree <= 3); --gate exits 1 naming each ratio over its bound. scripts/bench-map.mjs adds a re-map after one edited, committed file and takes --gate too.

Rejected.

  • Incremental linking (FR-001 as written). Link is 0.79 s of the 4.2 s, spread over adapters, and the largest, generic, is not per-file: member reach (memberReach) is a whole-family analysis whose result changes edges of files that did not change, the build graph, partial types and structural interfaces are global, and links run in sequence over one shared, mutated fact map (dropMemberAttrs, retractions). Re-linking "changed files and their dependents" needs a persisted reverse index per adapter and a proof per adapter that it is exact (FR-002); that is a redesign, not a slice. A per-adapter link cache keyed on its inputs does not help either: an edited C# file changes the inputs of generic and quality, which are 60% of link.
  • Compact edges (FR-003). Edges are 58 MB of the 250 MB nopCommerce store (table 31 MB, id index 13 MB, src and dst indexes 14 MB). A WITHOUT ROWID table keyed on (src, type, dst) without the text id would save about 29 MB, but it rebuilds the table: a breaks: true migration that older hooks in a running session cannot write (see the header of runtime/state/migrations.mjs). nopCommerce is within SC-002 (2.6 times the tree); the synthetic tiers are 50 times over because their files are a few hundred bytes, which no edge encoding fixes.
  • Caching the census's first-bytes classification by blob. It is the largest remaining cost of every re-map (and on a machine with an endpoint scanner, most of it), but it lowers no-change and changed maps alike, so it does not move scenario 2; a follow-up.
  • Faster fact ids (a cheaper hash): changes every stored fact id, which findings and evidence reference.

Summary

A re-map after a commit no longer re-reads the whole git history window, and the graph no longer stores clone fingerprints, so a small change hashes, writes and reloads less. The benchmark now gates the ratios #88 asks for. Scenario 2 is still not met on nopCommerce; see the map.

Refs #88

Measurements

Shared machine (load average 9 to 25, an endpoint scanner on every file open), so times are upper bounds; work counts and sizes are exact.

nopCommerce, main and this branch side by side on two clones, four committed one-file edits each, alternating; round 1 ran while the 50k benchmark saturated the disk and is left out:

Run main This branch
Re-map, one file edited (rounds 2 to 4) 3.4 / 3.8 / 3.9 s 3.0 / 3.0 / 3.0 s
after the census 2.4 to 2.8 s 2.0 s
history phase 0.37 to 0.39 s 0.07 s (1 commit read)
link / projection / derived (median) 0.68 / 0.52 / 0.32 s 0.55 / 0.43 / 0.29 s
Re-map, no change 1.1 to 1.4 s 1.1 to 1.3 s
Edited / no change, per round 3.1, 3.3, 2.4 2.7, 2.6, 2.4
Store after a cold map 250.5 MB 232.7 MB (2.4 times the 96 MB tree)

Synthetic tiers (scripts/bench.mjs):

Tier Run Cold No change 10 changed Store Gate
10k main 26.0 s 1.6 s 4.2 s 259 MB (no gate on main) 0.06, 2.6, 55
10k branch 14.9 s 1.5 s 3.8 s 245 MB 0.101, 2.50, 52.1: all three over
50k main 725 s 180 s 355 s 1,235 MB 0.25, 1.97, n/a
50k branch 147 s 14.9 s 19.4 s 1,238 MB 0.101 over, 1.30 within, 53.0 over

Read the 50k rows with care: the census (one file open per file, every map) was 180 s of the main no-change re-map, and 14.7 s against 7.5 s between the branch's own no-change and changed re-maps, run minutes apart. That swing, not this change, decides the 50k ratios here (the main 1.97 and the branch 1.30 both look met because the census dominates the denominator). The branch's changed re-map after the census is 8.6 s (extraction 2.2, link 2.5, projection 3.1, history 0.2). Roslyn was not re-run (the 50k tiers took the time available).

Scenario map

Scenario / requirement Status Evidence
1. No change at most 10% of cold Not met: 0.101 at 10k and at 50k (main 0.06 and 0.25) bench tables above; the no-change re-map is the census
2. 10 changed at most 2x no change Not met: 2.4 to 2.7 on nopCommerce, 2.5 at 10k; 1.30 at 50k only because that run's no-change census was twice its changed one as above; the remaining cost is extraction, link, projection, derived over the whole repository
3. Identical to a cold map Met remap-cost.test.mjs (edit, rename, deletion, moved reference; history read in part equals read in full), delta.test.mjs
4. Store at most 3x the tree at 50k Met on nopCommerce (2.4), not on the synthetic tiers (52 at 10k: files of a few hundred bytes) bench.mjs store_vs_tree
5. Previous store migrates Met, no schema change; old stores rewrite the quality module facts once full suite (upgrade test)
FR-001 incremental linking Not done see Rejected
FR-002 same graph as cold Met as scenario 3
FR-003 compact edges Not done see Rejected
FR-004 benchmark gates the ratios Met GATES and --gate in bench.mjs and bench-map.mjs, bench.test.mjs; CI runs --quick without --gate, since the bounds are not met yet

Testing steps

New tests (each fails on main, checked by running them against the old builder.mjs and quality/index.mjs):

  • tests/unit/graph/remap-cost.test.mjs "clone fingerprints serve the link and are not stored; a re-map after edits, a rename, a deletion and a moved reference equals a cold map": no fingerprints in facts or nodes, still in the per-file cache, clones found before and after a rename, and nodes, edges, facts and derived facts equal a cold map of the final tree after an edit, a git mv, a git rm and an import moved from one file to another.
  • same file, "a new commit reads only that commit from git, and the history equals one read in full": 4 commits read on the first map, 1 after one more commit, and with the per-commit cache cleared all 5 are read and the stored history facts are byte-identical (same generation, so the graph did not change).
  • tests/unit/scripts/bench.test.mjs "the bench gate checks the ratios of Make a re-map cost proportional to the change, with a compact store #88 against their bounds": inclusive bounds, each ratio over on its own.
  • tests/unit/policy/core-primitives.test.mjs "matcher answers as matchAny does".

The existing delta.test.mjs (delta re-map equals cold, five languages, add/delete/rename/test reclassification) and shallow-history.test.mjs pass unchanged.

Checks: the full npm test under the lock: 3,662 tests, 3,652 passed, 9 skipped, 1 failed (the known requireHumanTTY). The changed and nearby files alone: graph, quality, bench and glob tests pass. node scripts/bench.mjs --quick --gate runs end to end and exits 1 with all three ratios named.

Follow-up issues

What #88 still needs, and why it is not here:

  • FR-001 and scenario 2: incremental link, projection and derived facts. Needs a persisted reverse index per adapter (which files a file's edges depend on), starting with generic and its member reach; each its own change with an equality test.
  • Scenario 1 at scale: cache the census's first-bytes classification by blob, so a re-map stops opening every file (180 s of the 50k no-change re-map here).
  • FR-003 / scenario 4 on the synthetic tiers: compact edges need a breaking store migration; a person should decide when that is acceptable. The synthetic store/tree ratio is about per-file overhead on tiny files, not edges.
  • Run --gate on an idle machine (50k and Roslyn) for the published table; wire it into CI once the bounds are met.

Performance & Security & Data Privacy

Performance: as measured. Security and privacy: the per-commit cache holds paths, line counts and commit times that are already in the repository's git history, encrypted in the project's CAS like every cache blob, without the author hash. The fingerprints dropped from the graph stay in the encrypted per-file cache. Only public repositories were measured.

Feature flag

None. The graph equals a cold map of the same tree; module nodes lose attrs.fingerprints, which no command read; history.commits_read, tree_bytes, store_bytes and gate are added fields.

Review fixes

  • The per-commit history cache never keeps a shallow boundary commit (it lists every file as added, and has a parent after a deepen); COMMITS_VERSION is 2, so old caches are discarded.
  • Tests (tests/unit/graph/remap-cost.test.mjs): shallow clone, map, --unshallow, map equals a full read; and with history on, map through --deepen and a new commit equals a full read. Both failed before the fix.
  • FR-004 gate in CI: not added. bench.mjs --quick --gate fails on the 300-file fixture by design (no-change/cold about 0.2 vs 0.1, store/tree about 53 vs 3), so the gate stays a manual run on the 10k and 50k tiers.

🤖 Generated with Claude Code

QuintinBotes and others added 3 commits November 24, 2026 10:54
… graph, and gate the #88 ratios

The history step lists the window's commits and reads from git only those it has not seen before: a commit never changes, so its parsed changes are kept by sha (without the author hash). The quality adapter's fingerprints serve its link and stay in the per-file cache; the graph keeps the clones they find. Adapter file globs are compiled once per map. scripts/bench.mjs and scripts/bench-map.mjs report the three ratios of #88 with their bounds and fail with --gate when one is over; bench-map also times a re-map after one file is edited.

Refs #88

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs #88

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A boundary commit lists every file as added; after a deepen the same sha has a
parent and a different diff. Boundary commits are no longer stored, and
COMMITS_VERSION 2 discards caches that hold them. Tests cover a clone mapped
shallow, deepened and mapped again against a full read, with history on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@QuintinBotes
QuintinBotes merged commit 7c32668 into main Nov 24, 2026
12 checks passed
@QuintinBotes
QuintinBotes deleted the goal/88-incremental-linking branch November 24, 2026 11:23
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