docs(plans): record that the timing model was wrong in shape, not just magnitude

D7 predicted ~0.25% per step and called it invisible. Measured over a real
socket it is -3.9% on JSON hello and -2.1% on a three-step pipeline: the route
with *fewer* steps loses more, which falsifies a per-step model rather than
just its constant. Per-step work is skipped when nothing subscribes, so what
remains is a fixed per-request cost that a shallow route amortises over less.

The decision survived, for a better reason than it was made with: there is
nothing per-step left to make optional.

Also records the two regressions that measurement caught and reasoning did not,
both larger than anything the design anticipated — a second async frame in
handle() at 0.43us per request, and a closure allocated per request inside
correlateRequest at 0.16us. On this path an extra promise costs more than any
amount of bookkeeping.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-08-16 15:07:39 -05:00
1 parent 92987d0a24
commit 523e3184b0
2 files changed
+18 -2

No files matched your search

+16 -2
View File
@@ -111,12 +111,26 @@ Tasks 1–3 are the correction; 4–6 are what consumes it. Do not start 4 befor
**Step 4:** `route` on every payload is the **matched pattern**, never the concrete path. A metrics consumer labelling on raw URLs produces unbounded cardinality and takes down the metrics backend; the framework must not hand anyone that shape by default.
### Task 7: Benchmark, and publish the number
### Task 7: Benchmark, and publish the number — **DONE; D7 was wrong in shape**
**Files:**
- Modify: `BENCHMARKS.md`
`npm run bench` before and after, same box, same run. D7 predicts ~0.25% per step and predicts it is invisible against a 0.3% CV. If the measurement disagrees with the design, the design is what changes — say so rather than quietly keeping the code.
D7 predicted ~0.25% **per step**, invisible against the harness's own 0.3% CV. Measured over a real socket, on the box `BENCHMARKS.md` was produced on, same server config both sides:
| Scenario | Before | After | |
|---|---:|---:|---:|
| JSON hello | 78,118 req/s | 75,075 req/s | −3.9% |
| Pipeline (3 steps) | 70,671 req/s | 69,164 req/s | −2.1% |
**The route with fewer steps loses more**, which falsifies the model rather than only the number. The per-step cost is real but is skipped entirely when nothing subscribes (`Bus.hasListeners`); what remains is a **fixed per-request** cost — generating the request id, reading two headers, and the guard checks. A shallow route amortises that over less work, so it shows up larger.
Two regressions were found and fixed by measuring rather than reasoning, both larger than anything the design anticipated:
- **A second `async` frame in `handle()` cost 0.43 µs/request** — a promise and two microtask ticks, an order of magnitude more than the four `Map` lookups it existed to arrange. `handle()` is no longer `async`.
- **A closure allocated per request inside `correlateRequest`** cost 0.16 µs, 45% of the then-remaining overhead, for a helper capturing nothing.
Recorded here because the lesson generalises: on this path, an extra promise costs more than any amount of bookkeeping, and a hot-path prediction reasoned from primitive costs was off by more than 10×.
### Task 8: Documentation