7 min readPost 30
Why obit list slows down under concurrency: five causes, found by measuring in segments
Routing concurrent AI-agent hooks through our resident daemon slashed hook latency below 400 ms, yet obit list stayed stuck above 250 ms. Segment instrumentation exposed five surprises—including a 24 ms Cobra double-click tax, a 12 MiB GC ceiling smaller than one decode, and a fast path real ledgers never hit—bringing p95 down to 80–139 ms.

On this page
Moving concurrent AI-agent hook writes onto Obituary's resident daemon (obitd) cut 16-way single-hook latency from 1,049 ms down to ~393 ms. Yet one stubborn anomaly refused to budge: running read-only obit list alongside those hooks still hit 357 ms p95 against our 250 ms budget—and even 16 off-ledger PreToolUse hooks that touched neither Git nor the ledger pushed obit list to 215 ms.
Why was printing a table from a 1,000-entry local JSON file taking a third of a second? Between the evening of 23 November and noon on 24 November we instrumented every stage of obit list and uncovered five root causes nobody had predicted.
After fixing them, idle obit list p95 across single, 2, 4, 8, and 16 concurrent hooks fell from 191, 183, 178, 179, and 267 ms down to 84, 86, 80, 90, and 139 ms—cleanly below 250 ms across the board.

Segment probes: stdout took 0.46 ms; the blowup happened before main() and during decode
Timing every phase of obit list under single-run versus 16-hook contention upended our assumptions:
| Stage | Single-run median | 16-hook median |
|---|---|---|
Process creation to Go main() | 41.70 ms | 80.97 ms |
Hot store.json JSON decode | 19.59 ms | 44.84 ms |
| Reading both ledger files | — | 2.22 ms total |
| Table formatting | — | 1.34 ms |
| Writing stdout | — | 0.46 ms |

Because background host variance shifted identical binaries by over 100 ms between time windows, every subsequent comparison ran interleaved AB/BA pairs on the same machine.
Buried inside "command setup to list" sat a glaring 24 ms fixed tax: on Windows, Cobra calls mousetrap.StartedByExplorer() before parsing any subcommand to detect double-clicks—enumerating the entire system process snapshot twice (syscall.Getppid plus parent-name lookup). That single check burned 24.17 ms solo and 33.80 ms under 16 hooks (99.6% of command-setup time).
Skipping Cobra's check alone cut 25.68 ms off every solo run (42/42 wins), yet tail spikes still pushed 16-hook p95 from 305 to 355 ms. At the same time we calibrated our acceptance bar to real usage: 16 workspaces open rarely fire 16 hooks in the same millisecond, whereas 2 to 4 concurrent hooks reflect daily overlap. We kept the exact 250 ms p95 bar at 2–4 hooks and tracked 16 hooks as peak reference.
Interleaving four candidate arms in one run (against a noisy 833 ms baseline during a background disk scan) pinpointed where real gains lived:
| Arm | Change | Same-run 16-hook p95 |
|---|---|---|
| Baseline | Unmodified | 833 ms |
| a1 / a2 | Cheaper parent-process check before Cobra mousetrap | 852 / 887 ms |
| b | Resident daemon serves obit list over local IPC | 362 ms |
| c | Trimming package init | Unchanged |
| d | Fix projection fast path + raise resident memory cap | 737 ms (projection only) |
| Combined (a2 + b + d) | All three together | 329 ms |
Five root causes ranked by impact
1. Paying Cobra's 24 ms double-click tax on every invocation
Before Cobra parses flags, we now query the parent process image name directly from the Windows kernel and disable Cobra's check whenever it is definitely not explorer.exe (verified with test binaries named explorer.exe, Explorer.EXE, explorer.exe.bak.exe, and notexplorer.exe). Even obit --version dropped from 68.6 ms to 42.2 ms (versus 31.3 ms for an empty Go binary).
2. Repeating work the resident daemon already did
Opening services, reading store.json, decoding, and verifying the cold graveyard snapshot cost ~30 ms solo and double under contention. Routing obit list over the resident's current-user IPC endpoint delivered the largest single gain, falling back directly to byte-identical local reads whenever the resident is absent, older, busy, or times out.
3. A hardcoded 12 MiB daemon memory limit smaller than one decode
Decoding 1,000 active entries plus 1,000 graves exceeded obitd's fixed 12 MiB SetMemoryLimit, forcing the Go GC to thrash continuously—stretching decode from 3–5 ms to 6–16 ms and graveyard summaries from 7–9 ms to 18–39 ms.
Scaling the memory cap dynamically to 64× store.json (32 MiB floor, 512 MiB ceiling) dropped 4-hook p95 on a real-shape ledger from 111.6 ms to 80.1 ms all by itself.
4. The biggest surprise: real ledgers had never hit the fast read path
Every real grave written by obit bury carried longNames, parentRef, operationRef, originRef, and lookup tables—which caused strict projection decoding to fail with "unknown field" and silently fall back to full cold-snapshot deserialization. Earlier synthetic test seeds omitted those fields and hid the bug completely.
Teaching the projection to accept those fields and validate table index bounds (relying on SHA-256 verification instead of re-parsing static lookup bodies) cut even resident-free solo list median from 139.4 ms to 123.3 ms.
5. The irreducible OS process-creation floor
An empty Go binary takes 28.4–39.4 ms from spawn to main(). Of the 7–12 ms obit adds, 5–6 ms is package init, led by net's WSAStartup (3.1–4.8 ms, pulled in by pflag, go-winio, and the MCP SDK). A stripped 12 MB binary holding only list and hook still spent 4.7–7.2 ms in init—not worth splitting binaries.
Final numbers: below 250 ms across idle and busy hosts
42 waves per level on a real-shape 1k+1k ledger:
| Concurrency | Before p50 / p95 | Final p50 / p95 | Over 250 ms (before / after) |
|---|---|---|---|
| Solo | 166.2 / 191.4 ms | 72.2 / 84.2 ms | 0 / 0 |
| 2 hooks (gate) | 158.1 / 182.6 ms | 72.3 / 86.1 ms | 0 / 0 |
| 4 hooks (gate) | 155.3 / 177.9 ms | 67.8 / 80.1 ms | 0 / 0 |
| 8 hooks | 164.3 / 178.9 ms | 76.9 / 89.9 ms | 1 / 0 |
| 16 hooks (peak ref) | 229.1 / 266.7 ms | 97.2 / 139.0 ms | 9 / 0 |
At 10k+10k entries (12 waves), solo p95 fell from 429.0 to 225.9 ms and 4-hook p95 from 449.0 to 241.7 ms. Under a heavy background disk scan (51–84% CPU), 2- and 4-hook p95 stayed at 219.5 and 222.0 ms (down from 401.5 and 508.3 ms), with 16-hook dropping from 833.0 to 328.9 ms.
Trade-offs stay clean: protocol v1 remains backwards-compatible, concurrent hooks got slightly faster too, resident working set rose ~10 MB (25–27 MB → 35–39 MB) from the 32 MiB floor, and every request decodes fresh store.json while reusing the immutable cold graveyard parse only when hash, size, and mtime match verbatim (tampered sizes fail closed under mutation tests).