A dozen agents writing at once: measure where it is slow before changing anything
Running a dozen AI coding agents simultaneously slowed Obituary's hooks to a crawl. Before rewriting storage, we profiled real hook processes and real Git under load—discovering 1,049 ms single-hook p95 and 469 ms list latency at 16 concurrent writers—then gated five optimization batches on paired benchmarks and shipped Batch A the same day.
Pre-optimization p95 latencies under 4, 8, and 16 concurrent hooks, compared against our 600 / 800 / 250 ms target gates at 16-way load.On this page
Run a single AI coding agent and Obituary's local hooks feel invisible. Open a dozen agents at once, and every file edit spawns a fresh obit hook process that checks Git and updates the local JSON ledger (store.json)—turning crisp terminal output and obit list noticeably sluggish.
Early on 22 November we resisted the urge to jump straight into a storage rewrite and profiled the real system end to end first.
On a ledger with 1,000 active entries and 1,000 graves, 16 concurrent hooks pushed single-hook p95 to 1,049 ms and a concurrent obit list to 469 ms.
Our benchmark drove real obit hook claude (PostToolUse in a consented project), real Git, and real NTFS file IDs inside isolated temp directories. Each wave launched k hooks staggered at 0, 5, 10, and 15 ms, fired a real obit list 65 ms later, and ran 7 waves per level:
Concurrent hooks
Whole-wave p95
Single-hook p95
Concurrent obit list p95
4
504 ms
438 ms
288 ms
8
584 ms
560 ms
228 ms
16
1,272 ms
1,049 ms
469 ms
Across 112 writes at 16-way concurrency, 1 write exceeded its lock budget and completed via the existing replay queue—112/112 matched with zero lost items, yet latency was far past what an editor hook should cost.
Pre-optimization p95 latencies under 4, 8, and 16 concurrent hooks, compared against our 600 / 800 / 250 ms target gates at 16-way load.
Where the time went: lock queueing and per-hook Git, not JSON parsing
Breaking the latency down showed no single step looked outrageous in isolation:
Empty Go binary spawn-to-exit: 33.4 ms median, 48.3 ms p95.
Ordinary off-ledger PreToolUse hook: 48.0 ms median, 68.5 ms p95.
All Go package init() calls combined: 11.0 ms median (i18n 4.7 ms, net 3.7 ms).
Scaling ledger size tenfold from 1k+1k to 10k+10k exposed linear rewrite growth (medians):
Ledger operation (median)
1,000 + 1,000 entries
10,000 + 10,000 entries
Read hot store.json
4.3 ms
35.9 ms
Read full hot + cold snapshot
12.3 ms
111.4 ms
Update one revision and commit
14.3 ms
82.2 ms
Directory burial compounded the stall: on 10,000 entries, a reader waiting purely for the shared lock (without even decoding JSON) waited 2,043 ms median (2,500 ms p95), and an unlocked single-threaded identity walk across 10,000 files alone took 1,728 ms.
Neither loosening hook timeouts nor swapping JSON libraries could fix 16-way contention: every hook process was lining up for the full-ledger lock and spawning its own Git subprocesses.
Five gated batches: no merge without paired numbers
We broke optimization into five independently verifiable batches (A–E), each bound to paired same-machine gates:
Batch
Focus
Merge gate
A
Keep JSON format unchanged: lazy hook subcommand init, on-demand i18n, display-projection reads for list
Ordinary PreToolUse median down ≥ 4 ms with no p95 regression; 10k+10k list p95 heading under 300 ms
Persistent 1-row update at 10k entries p95 ≤ 15 ms; single-process scattered writes not slower than JSON
C
Resident daemon as single writer; hooks exit on durable receipt
1k+1k at 16 concurrent hooks: hook p95 ≤ 600 ms (stretch 300), wave ≤ 800 ms, concurrent list ≤ 250 ms
D
Trim directory burial and doctor lock stalls
Extra reader wait during 10k directory burial p95 < 100 ms
E
Evidence-gated micro-optimizations
≥ 10% paired gain on the same machine
Three anti-shortcut rules stayed locked: zero skipped per-item identity checks during directory burial; hooks must hold a durable on-disk receipt before exiting (returning early without durability fails the gate); and no schema-changing batch ships standalone. A quick named-pipe storage prototype confirmed the single-writer thesis: 16 clients hitting 10k rows fell from 60.8 ms per commit to 8.8 ms with a 2 ms / 32-item batch window.
Shipping Batch A the same day with zero format changes
At 18:38 on 22 November, Batch A merged cleanly with zero schema changes and zero new dependencies:
Lazy hook startup: main.go previously constructed all 30+ subcommands and loaded localized help and config before recognizing a hook call, while i18n parsed both JSON catalogs at package init. Loading only the hook command path and wrapping catalog parsing in sync.OnceValue kept ordinary hooks lean.
Projection reads for list and summaries: cold graveyard snapshot bytes, SHA-256 hashes, ownership markers, IDs, and safety indices are still verified in full, without unmarshaling unused nested fields; any legacy ledger or unsupported evidence falls back to full reads, and all write paths stay untouched.
Paired AB/BA runs on the same machine (identical binary names, 2 warm-up pairs, zero outliers discarded):
The gates paid for themselves before Batch A even landed:
Rejected an intermediate build: hook p95 had dropped to 56.39 ms, yet 10k list p95 still sat at 567 ms; we held the branch until list dropped to 265.40 ms.
Red-first snapshot corruption test: setting parentRef = -1 inside a cold snapshot and recomputing its hash initially fooled the projection into reporting healthy; adding bounds verification turned the test green, alongside 44 byte-identical bilingual CLI checks, 3 new compile-time mutants, and full 3-OS CI.
Batch A cleared startup and read waste cleanly, leaving multi-hook lock queueing and repeated Git spawns for the resident-writer phase next.