Route ranking at build time, and a benchmark that can measure a release #87
3
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
e61771077c |
docs(bench): refresh the tables and record what moved between releases
The tables were measured on 2026-07-07 at `fe1831a`, two releases ago. Re-measured at `8c5855c` with the runtime matrix included, every row under 1.2% CV. The headline is not in the cross-framework tables. green-tea sits within 2% of fastify on `hello` and `param` and second only to `raw-http` on `validate` — but the same application on Deno serves 153,408 req/s against Node's 90,976, and on Bun 131,674. Node's own `http` module with no framework manages 119,357. The runtime-neutral boundary that costs on Node is what makes those rows possible, and until this run nothing measured them. The notes below the marker say what a table cannot. In order: the release gate — this release is neutral against `26.8.0-beta.1` on every scenario but the CORS preflight, which gains 2.7%; the interval against `26.7`, which is roughly −5% to −8% and is **not** a regression, because July matched routes by splitting a string in one flat file and had no constraints, no specificity, no correlation and one adapter; the figures recorded in the code when each change landed, including one that reached 45% of a request before it was fixed; and what is still unattributed, which is most of it. That last part is the point. Three candidates were measured and none of them explain the interval: `randomUUID` is 0.7% and lands within noise, replacing specificity ranking with July's first-match-wins is noise, and the bundle versus the source is noise. A section that explained everything would be a defence. This one says what was found and what was not. The measurements were always there — `core.ts`, `bus.ts`, `pipeline.ts`, `headers.ts`, `body.ts`, `router.ts` all carry them, with alternatives compared and rejected. They cite different baselines, 4.4 µs to 10.19 µs, because each was taken against whatever a request cost that day, so they cannot be added up. What was missing was never rigour. It was a number per version against a fixed baseline, in the file where the question gets asked. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com> |
||
|
|
9c78842684 |
test(bench): measure a release against the last one, and every runtime it claims
`BENCHMARKS.md` answered "how does this compare to fastify" and nothing answered "did the last two months cost anything". Those are different questions and the second one is the one a release has to pass, so it needed its own tool rather than a second reading of the first one's table. `npm run bench:compare` runs two worktrees of this repository against each other on one box in one sitting, alternating which side goes first each round so drift lands on both rather than on whichever ran second. It shares one `node_modules` and one byte-identical server file, which holds everything except `src/` constant — and is only sound while `package.json` has not moved between the revisions, which the header says out loud. Three things it refuses to do quietly, each of which it did once before being taught not to: - A run whose connections all errored reports 0 req/s, and a median absorbs that without complaint. Non-2xx, errors and timeouts now fail the case, and so does a zero. Not on the warmup, which exists to absorb exactly the cold-start noise a fresh server produces. - A range-overlap check flags a row as directional, and its own documentation says to treat that as "measure it again", never as a result. Three samples of two overlapping distributions separate by chance often enough to have produced a regression report that five rounds then erased. - `cors.origins` invocations are counted rather than timed. The benchmark's predicate is a `Set` lookup, so calls saved are invisible in req/s — but the option takes a function so it can be a lookup, and there the same saving is a network round trip. **The runtime servers finally run.** `bench/servers/green-tea-deno.ts` and `-bun.ts` were written in July and referenced by nothing — not the runner, not a script, not CI. The runner only knew how to launch Node, so both sat there looking like coverage the table did not have. Launchers are per runtime now and they get their own section, kept out of the cross-framework tables because a green-tea-on-Bun row beside fastify-on-Node reads as a comparison nobody made. `green-tea-node.ts` is new and loads `dist/` like its Deno and Bun counterparts. The runtimes table exists to vary the runtime, and a Node row reading `src/` through tsx would have varied the load form at the same time. A route-table-width dimension, because every matcher cost scales with how many candidates a request walks past and the tables here use six routes. Three separate matcher findings measured as noise before this existed, which said nothing about them and everything about the instrument. Finally, `run.ts` preserves whatever sits below a marker instead of overwriting the file whole. The tables answer what is true today; the notes below them carry which release moved a number and what the move bought, and regenerating used to delete that silently. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com> |
||
|
|
8c5855c59e |
perf(router): settle route ranking when the table is built, not per request
Route matching scanned every method-matching route on every request and ranked the
candidates as it went, calling `moreSpecific` — two `compilePattern` lookups each — per
candidate. Both the scan and the ranking scale with the size of the route table, and the
answer they compute cannot change between requests: the table is assembled once, after the
graph is prepared, and handed to the adapter unchanged.
So the ranking moves to where the table is built. Routes are compiled, bucketed by method
and sorted most-specific-first, and matching walks until the first match and returns it.
`sort` is stable, so patterns of equal specificity keep registration order — which is what
the old scan produced by refusing to replace its best on a tie.
Measured on a request to a parameterised route registered last, against the same tree
without these changes, medians of five and seven rounds:
6 routes no change (every row overlaps)
50 routes +3.3%, +3.5% across two runs
200 routes +14.9%, +12.0% — twelve rounds, not one crossing sample
The shape is the point rather than any single number: the saving is proportional to how
many candidates a request walks past, so it is invisible on a small table by construction.
That is also why it went unnoticed. The benchmark had no route-table-width dimension until
this commit added one, so every matcher change measured as noise no matter how real.
Two smaller savings on the same path. `decodeSegment` now skips `decodeURIComponent` when
the segment holds no `%`, the same gate `normalizeRequestPath` already applies to the whole
path for the same reason. And decoding memoizes per request rather than per candidate: a
scan reaching the same parameter position on several routes used to decode the same string
once per route, and position is all decoding depends on.
`allStatic` is deleted. It short-circuited the scan on an all-literal match, which sorting
subsumes — such a pattern now sorts first and wins by position.
The index is keyed by the identity of the route array, so it is built once and collected
with the table it describes. A table assembled fresh — mesh splicing a teapot's exports in
at boot — is a different array and gets its own index, so no caller has to invalidate
anything.
`matchRoute precedence` already covered the ordering this rewrite had to preserve, and it
passes unchanged. Two cases were missing and are added: that equal specificity keeps
registration order, which is the property the stable sort now carries, and that a parameter
decodes to the same value however many candidates the scan walks. Both pass against the
previous implementation too — they describe behaviour that already existed, which is what
makes them evidence the rewrite preserved it rather than evidence of the change.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
|