Skip to content
LegacyExodus

From 11.3 GB to 1.0 GB: analysing whole repositories in bounded memory

7,172 files of Ghost v6.73.0, every fact kept, and memory that no longer holds the whole run at once. What changed, how it was measured, and what is still not bounded.

November 9, 20263 min readScalability · Systems

A static analyzer that only works on small repositories is a demo. The systems worth modernizing are large, so we benchmark on Ghost v6.73.0: 9,171 files, 7,172 of them JavaScript and TypeScript the engine analyses. Before the work described here, a fresh analysis of it peaked at 9.6 GB, and reusing a stored snapshot of it peaked at 11.3 GB.

Why memory grew with the repository

Every stage built its full output as in-memory lists: every call, every reference, every control-flow and data-flow graph of the run. Removing waste made the engine three times faster, but it could not change the shape: peak memory was the sum of all facts, so a repository fifty times larger would not fit on any machine.

Fact lists on disk (ADR-009)

  • Whole-run lists are written once, as one JSON document per line, and become immutable handles. Reading one yields one item at a time.
  • Lists that must be sorted are sorted in bounded runs and merged, so the order equals a stable in-memory sort without holding every item.
  • Records hold handles, not arrays. A handle's identity is the SHA-256 of its lines, so storage can address it without reading it.
  • Every step merged only with a fact-diff of zero lost and zero gained facts, on Ghost as well as the CI corpora.

Reuse that verifies while it copies (ADR-011)

Reusing a snapshot has to answer one question safely: are the bytes I am about to read the bytes I verified? The old answer was to read every artifact into memory, hash it, and keep the bytes. That was safe and cost gigabytes. Now each fact artifact is hashed while it is copied into the run's private scratch space, and only that copy is read afterwards. Its lists are then streamed back into disk lists, with every item validated as it passes, so a single malformed fact still refuses the whole snapshot.

Fresh analysis
Before9.6 GB
After1.8 GB
Snapshot reuse
Before11.3 GB
After1.0 GB
Peak memory on Ghost v6.73.0, 7,172 analysed files.
RunBeforeAfter
Fresh analysis, peak memory9.6 GB1.8 GB
Snapshot reuse, peak memory11.3 GB1.0 GB
Snapshot reuse, time79 s25 s
Ghost v6.73.0, one engine process per run, same machine. Source: the engine's ADR-009 and ADR-011 measurements.

Reuse is now 11.5× smaller and 3.2× faster, and it costs less than analysing from scratch, which is the invariant the design asked for.

Held by a gate, not by a promise

CI analyses a synthetic repository of 10,000 files on every pull request, then reuses its snapshot in a second process, because a process cannot reset its own peak. On the CI runner the fresh run peaks at 1,038 MiB against a ceiling of 2,800, and reuse at 708 MiB against 1,800. A change that brings back whole-run state fails the build.

Run the same checks on your codebase.