Route matching is a linear scan today. A tree is a requirement for stable: Fastify (find-my-way), Hono and h3 (rou3) all match through a tree or a precompiled matcher, and they are what green-tea gets compared with.
Where it costs, in src/http/router.ts:
matchRoute walks the method's routes, sorted by specificity, until the first match, so every request is O(routes before its own).
allowedMethods, used for every 404/405/OPTIONS, walks all routes and runs compilePattern for each one on every call. An attacker picks the misses.
WebSocket routes are matched separately (matchWsRoute).
What must not change: precedence (static > constrained > plain param > catch-all), ties in registration order, the safe-regex constraint subset, implicit HEAD from buffered GET, the canonical Allow, the 400s for // and malformed encoding, the ambiguity checks at boot, and mesh splicing routes into a fresh table. test/router.test.ts and the parity suite are the contract, and they have to pass unmodified.
Also: one tree per method, plus a method set at each leaf so allowedMethods is a single lookup. WS routes go in the same structure. Bench before and after with npm run bench, reported both ways.
Lands before rc.1. The public API does not change, but it is the largest behaviour-risk change left.
Route matching is a linear scan today. A tree is a requirement for stable: Fastify (find-my-way), Hono and h3 (rou3) all match through a tree or a precompiled matcher, and they are what green-tea gets compared with.
Where it costs, in src/http/router.ts:
- `matchRoute` walks the method's routes, sorted by specificity, until the first match, so every request is O(routes before its own).
- `allowedMethods`, used for every 404/405/OPTIONS, walks **all** routes and runs `compilePattern` for each one on every call. An attacker picks the misses.
- WebSocket routes are matched separately (`matchWsRoute`).
**What must not change:** precedence (static > constrained > plain param > catch-all), ties in registration order, the safe-regex constraint subset, implicit HEAD from buffered GET, the canonical `Allow`, the 400s for `//` and malformed encoding, the ambiguity checks at boot, and mesh splicing routes into a fresh table. `test/router.test.ts` and the parity suite are the contract, and they have to pass unmodified.
**Also:** one tree per method, plus a method set at each leaf so `allowedMethods` is a single lookup. WS routes go in the same structure. Bench before and after with `npm run bench`, reported both ways.
**Lands before rc.1.** The public API does not change, but it is the largest behaviour-risk change left.
Fixed in 26.11.0-rc.1 (2e2c68d, a64f514, 7a9932f). From the changelog:
HTTP route lookup uses a radix index (#109). The router used to scan a specificity-sorted list per method, and on every 404 and 405 it recompiled and matched every route to build Allow. It now walks a tree per method, built once from the route table, with mesh routes from teapots in a tree of their own. This is internal and changes no behaviour: the same route wins, with the same params, Allow, implicit HEAD and 404/405, checked against the frozen parity corpus. graph(), explain() and openapi() still read the declared routes, not the tree. Median lookup time against the old matcher (jarvis, bench:lookup): at 500 routes, static hit −54%, late param hit −88%, method miss −94%, path miss −96%; at 10 routes, every cell is within noise or faster (late param hit +3.4%, 95% CI −5.0…+12.6%).
Fixed in **26.11.0-rc.1** (`2e2c68d`, `a64f514`, `7a9932f`). From the changelog:
- **HTTP route lookup uses a radix index** (#109). The router used to scan a specificity-sorted list per method, and on every 404 and 405 it recompiled and matched every route to build `Allow`. It now walks a tree per method, built once from the route table, with mesh routes from teapots in a tree of their own. This is internal and changes no behaviour: the same route wins, with the same params, `Allow`, implicit `HEAD` and 404/405, checked against the frozen parity corpus. `graph()`, `explain()` and `openapi()` still read the declared routes, not the tree. Median lookup time against the old matcher (jarvis, `bench:lookup`): at 500 routes, static hit −54%, late param hit −88%, method miss −94%, path miss −96%; at 10 routes, every cell is within noise or faster (late param hit +3.4%, 95% CI −5.0…+12.6%).
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Route matching is a linear scan today. A tree is a requirement for stable: Fastify (find-my-way), Hono and h3 (rou3) all match through a tree or a precompiled matcher, and they are what green-tea gets compared with.
Where it costs, in src/http/router.ts:
matchRoutewalks the method's routes, sorted by specificity, until the first match, so every request is O(routes before its own).allowedMethods, used for every 404/405/OPTIONS, walks all routes and runscompilePatternfor each one on every call. An attacker picks the misses.matchWsRoute).What must not change: precedence (static > constrained > plain param > catch-all), ties in registration order, the safe-regex constraint subset, implicit HEAD from buffered GET, the canonical
Allow, the 400s for//and malformed encoding, the ambiguity checks at boot, and mesh splicing routes into a fresh table.test/router.test.tsand the parity suite are the contract, and they have to pass unmodified.Also: one tree per method, plus a method set at each leaf so
allowedMethodsis a single lookup. WS routes go in the same structure. Bench before and after withnpm run bench, reported both ways.Lands before rc.1. The public API does not change, but it is the largest behaviour-risk change left.
Fixed in 26.11.0-rc.1 (
2e2c68d,a64f514,7a9932f). From the changelog:Allow. It now walks a tree per method, built once from the route table, with mesh routes from teapots in a tree of their own. This is internal and changes no behaviour: the same route wins, with the same params,Allow, implicitHEADand 404/405, checked against the frozen parity corpus.graph(),explain()andopenapi()still read the declared routes, not the tree. Median lookup time against the old matcher (jarvis,bench:lookup): at 500 routes, static hit −54%, late param hit −88%, method miss −94%, path miss −96%; at 10 routes, every cell is within noise or faster (late param hit +3.4%, 95% CI −5.0…+12.6%).