THE WHITE DRAGON BOOK · CHAPTER 04

Chapter 4: Content-Addressed Compilation (.b8p CAS Packs & Zero-Q Lookup)

CH. 4 · .b8p CAS & ZERO-GOMA .b8p BLAKE3 CAS ZERO-GOMA CACHE Local O(1) Digest Hit No RPC Daemon Overhead Deterministic Artifact
Vector Architecture Diagram · asset-ch04

Chapter 4: Content-Addressed Compilation (.b8p CAS Packs & Zero-Q Lookup)

Lineage: Green/Red/Purple Dragon (make Timestamps & Remote Build Farms) → White Dragon (Deterministic Local .b8p CAS Packs)
Live Proof: packages/@awesome-os/b8g-cxx/README.md & b8g-deps-engine.mts (8.04 ms on Google's 4,968-line DEPS)

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:

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:

// 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:

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.

← Back to White Dragon Book index