Chapter 4: Content-Addressed Compilation (.b8p CAS Packs & Zero-Q Lookup)
Chapter 4: Content-Addressed Compilation (.b8p CAS Packs & Zero-Q Lookup)
Lineage: Green/Red/Purple Dragon (makeTimestamps & Remote Build Farms) → White Dragon (Deterministic Local.b8pCAS Packs)
Live Proof:packages/@awesome-os/b8g-cxx/README.md&b8g-deps-engine.mts(8.04 mson Google's 4,968-lineDEPS)
4.1 Why mtime and Remote Build Farms Are Band-Aids
Classical build systems — from 1976 make to modern Ninja + Goma/RBE — still answer the wrong question: "Is file A.cc newer on disk than A.obj?"
Timestamp-driven builds fail in three catastrophic ways:
- False Invalidation: Switching git branches, touching a comment, or editing a single function in a 3,000-line
.ccfile forces the entire translation unit to recompile. - Header Cascade: Editing one unrelated declaration in a shared header invalidates every TU that transitively includes it.
- Cloud Latency Tax: Instead of fixing the granularity of compilation, Von Neumann teams ship gigabytes of preprocessed
.ccfiles to remote RBE clusters — paying network RTT, serialization overhead, and cloud bills just to runclangelsewhere.
The White Dragon Principle: Never ask when a file changed. Ask what cryptographic hash each semantic block and transitive header closure has — and store the compiled artifacts in a local, zero-copy .b8p (0x50473842 'B8GP') WASM Trie CAS pack.
4.2 Anatomy of a .b8p CAS Object Pack
@awesome-os/b8g-cxx replaces loose .obj directory trees with target-bucketed .b8g-cas/*.b8p packs containing a /.b8oc-index.json manifest and /cas/<sha256>.obj payloads. Every lookup is computed from three deterministic layers:
- Deduplicated
HeaderDigestSlab: Parses#includeclosures in RAM once per build wave, hashing each header's normalized content exactly once instead of per-TU. - Shared Transitive PCH (
/Yc+/Yu/Fp): Automatically synthesizes a content-keyed precompiled header for the common include preamble across a target bucket. - Sub-TU Code-Block Chunking (
cc-block-chunker.mts): Splits a C++.ccfile into top-level function/class blocks, hashes each block independently, compiles only the mutated block against the cached PCH, and merges cached + fresh block.objs vialld-link /lib.
// packages/@awesome-os/b8g-cxx — Sub-TU Content-Addressed Block Pipeline
import { splitCxxSourceIntoBlocks, compileCxxUnitByBlocks } from '@awesome-os/b8g-cxx/blocks'
import { B8pObjCache, HeaderDigestSlab } from '@awesome-os/b8g-cxx/cas'
const slab = new HeaderDigestSlab()
const cache = await B8pObjCache.open('.b8g-cas/v8-cctest.b8p')
// 1. Split translation unit into independently hashable top-level code blocks
const blocks = splitCxxSourceIntoBlocks(sourceText)
// 2. Hash (compilerFlags + pchDigest + blockNormalizedText) -> SHA-256 CAS key
// On a 3-block .cc with 1 edited function: 2 CAS hits, 1 block compiled (< 190 ms)
const result = await compileCxxUnitByBlocks({
unitPath: 'src/objects/js-array.cc',
blocks,
headerSlab: slab,
casPack: cache,
reuseSharedPch: true,
})
4.3 Interface Stubs (!ifs-v1 / .api.digest) & 8.04 ms DEPS Resolution
Content-addressed caching only reaches full leverage when downstream link steps stop invalidating on private implementation edits. @awesome-os/b8g-cxx/stubs emits four deterministic artifacts from a shared library's public C-ABI surface:
v8.ifs(!ifs-v1textual ELF/COFF interface stub) andv8.def(30exported symbols includingb8g_v8_fastcall_no_receiver).v8.api.digest(SHA-256 of the exported ABI surface; if unchanged, downstream linkers skip relinking completely).v8.stub.lib(COFF import library compiled directly from the stub, enabling90.52 mszero-v8.hconsumer compiles).
The same content-addressed discipline applies to dependency graphs. Traditional gclient sync invokes Python subprocesses and network round-trips over Chromium's 4,968-line DEPS file. b8g-deps-engine.mts evaluates the entire DEPS graph deterministically in memory in 8.04 ms, resolving every pinned revision against local .b8p (0x50473842 'B8GP') CAS hashes with zero redundant I/O.
4.4 Measured Benchmarks (V8 15.6.77, Windows 11 x64, 8 Workers)
| Build / Cache Operation | Classical Von Neumann (Ninja / mtime) |
White Dragon (@awesome-os/b8g-cxx .b8p CAS) |
|---|---|---|
Chromium DEPS Graph Eval (4,968 lines) |
Seconds (gclient Python + disk stat) |
8.04 ms (in-memory deterministic eval) |
Dry-Run Wave Plan (1,859 V8 TUs) |
Multi-second manifest stat | 0.50 s (496 ms) |
Warm No-Op Check (cctest.exe + stubs) |
Full Ninja stat + link check | 0.45 s (449 ms) |
Warm .b8p CAS Restore (50 deleted .objs) |
Recompile 50 TUs (~2–4 min) | 14.42 s (0 compiles, 53 CAS hits) |
Sub-TU Single-Function Edit (3-block .cc) |
Full TU reparse + recompile (3–12 s) |
< 190 ms (2 CAS hits, 1 block, pchReused=true) |
Cross-Revision Reuse (15.6.75.32 → 15.6.77) |
Full rebuild on branch switch | 646 / 1,859 (34.7%) instant reuse in 7.66 s |
Content-addressed .b8p packs collapse compile times to milliseconds. Yet even a 170 ms compile is wasted if you still stall behind a disk-bound linker. In Chapter 5, we abolish disk linking altogether with W^X (RW → RX) In-Memory Linking & Lazy Trampolines.