Sage · anchoring engine · build step 1

Checking agent memory against 100,000 files, faster than git

Every time a coding agent starts a session, Sage checks whether the files behind each remembered belief have changed. The build plan's budget was 300 ms on a 100k-file repo with a warm cache. Timed from outside, with process start-up included, the check now beats git status.

47ms Warm check on 100,000 files: old commit against the working tree, untracked files included. Mean of 50 runs with hyperfine -N, as an outside process.
300 ms budget ▼
▲ 47 ms, about a sixth of the budget
Key figures
faster than git 1.7× faster than git status 47.0 ms vs 80.8 ms, both timed from outside.
2.6× faster than git diff t0 The question Sage's check actually answers: 123.6 ms in git.
45 → 0.5 ms Freeing the snapshots 100k-entry hash maps replaced by sorted flat tables.
identical 202 / 202 Non-Same results agree Native, through git status, and with the cache off.
Against git

Timed the same way as git, Sage is the fastest line

Each command is started directly by hyperfine (-N, no shell), 5 warm-up runs and 50 timed runs. Plain git diff does strictly less work than Sage: it never looks for untracked files or compares against an older commit.

Terminal screenshot of the hyperfine run: git status 80.8 ms, git diff 52.7 ms, git diff t0 123.6 ms, sage check 47.0 ms
The run behind the chart, as the terminal showed it.
Same binary, same moment

The native status path is more than twice as fast as asking git

Building the checker, in-process≈2.3× faster
The same warm example, back to back. SAGE_GIT_STATUS=1 forces the git status path.
through git status 83–87 ms
native 36–40 ms
Freeing everything at exit≈90× less
A short-lived hook pays this on every run, and timing from outside includes it.
hash maps ~45 ms
sorted tables 0.4–1.0 ms
Terminal screenshot: five native runs of 36 to 41 ms with free 0.5 ms, then three runs through git status of 84 to 87 ms
Where the time went

Seven costs, seven fixes

git ls-tree, twice · 365 ms each A commit's file list never changes, so it is cached under the commit's id.
git diff against the working tree · 131 ms Replaced by the cached commit-to-commit diff plus the renames staged in the index.
git status · 80–135 ms Read .git/index directly and scan the disk in parallel. Each directory's tracked files are one sorted run of the index, and ignore rules only run for untracked paths. Anything unusual falls back to git.
Hash maps of 100k strings · ~45 ms to free Snapshots are sorted flat tables: all paths in one buffer, all blob ids in another. Two snapshots compare in one merge pass.
A hex string per index entry · ~6 ms Ids are hex-encoded straight into the table. Reading the index: 16 → 10 ms.
"Is there a .gitignore here?" per directory · ~5 ms The directory listing already says so. Tracked files are settled as it streams. Scan: 25 → 20 ms.
Starting git for HEAD and revisions · ~19 ms each HEAD is read from the ref files, and a commit id verified once is not checked again.
Correctness

Same answers, whichever path computes them

Every file at t0 is an anchor, checked against the working tree three ways. All three agree on every per-file result. Differential tests also hold the native snapshot equal to git status on edits, deletions, untracked files, nested ignore rules, force-added files and case-only renames.

Anchor statusNativeVia git statusCache off
Same99,79999,79999,799match
Relocated (moved)100100100match
Gone (deleted)100100100match
Modified111match
Terminal screenshot: native, git-status and no-cache give the same counts, and the per-file results are identical
Terminal screenshot: differential tests pass, clippy is clean, and the workspace has 127, 5 and 23 passing tests
155 tests across the workspace, 127 in the anchoring engine.
On a real repo

Re-checking a search on ky

A search behind a belief is re-run only over files that changed. Across 40 commits of sindresorhus/ky, Sage re-searched 20 changed files in about 50 ms, and the result matched git grep at both commits (the same 14 files).

Raw output
> hyperfine -N --warmup 5 --runs 50 --export-markdown race.md ...
| Command                           | Mean [ms]    | Change | Factor        |
|:----------------------------------|-------------:|-------:|:--------------|
| git status                        | 80.8 ± 2.2   |        |               |
| git diff                          | 52.7 ± 3.9   | -34.8% | (1.5x faster) |
| git diff t0                       | 123.6 ± 11.9 | +52.9% | (1.5x slower) |
| sage check (t0 -> working tree)   | 47.0 ± 3.6   | -41.9% | (1.7x faster) |
Share card
Sage · agent memory that checks itself
47 ms
to check what an AI agent remembers against 100,000 files. 1.7× faster than git status.
hyperfine -N, 50 runs, process start included · same answers as git
Windows laptop, synthetic 100k-file repo
Method

Measured 13 Oct 2026 on a Ryzen 5 5600H (12 threads), Windows 11, git 2.46.0, hyperfine 2.0.0. The test repo is built by bench/make_repo.py: 1,000 folders of 100 one-line TypeScript files, then a commit that moves 100 files, deletes 100 and edits 1. Tree ids depend only on content, and a rebuild from the script matched the measured repo exactly (t0^{tree} 1965611…, HEAD^{tree} f117aec…).

Every timing in the race comes from hyperfine -N, so git and Sage pay the same process start-up (an empty process takes about 6 ms here). Sage is given t0's commit id, as its ledger stores ids; resolving a tag would start git first. Screenshots were taken of a real Windows Terminal window by bench/capture.ps1, running bench/run.sh. Real repos have larger files and messier histories, and git is faster on Linux and macOS, so expect different ratios there.