From 9fdf14acd6a3fd605707ff6b94f2588f049f2c11 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 12:07:48 +0000 Subject: [PATCH] refactor(router): build a method's tree in match, without a helper `build` was a two-line function called only from `match`. Each function costs V8 about 15k instructions to set up at import and again when it is first compiled, so folding it in makes the module smaller and the first request that builds a tree cheaper. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VVaw7Sutbw6xMTMyDFeNfw --- packages/router/src/index.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/router/src/index.ts b/packages/router/src/index.ts index 929c21e..c6af03f 100644 --- a/packages/router/src/index.ts +++ b/packages/router/src/index.ts @@ -171,8 +171,12 @@ export class Router { return undefined } + // Adds the routes in `pending` to the tree. Once the tree has served a + // request, each goes in whole, as routes may no longer wait where the tree + // has grown past them. if (routes.pending.length > 0) { - build(routes) + expand(routes.root, routes.pending, 1, routes.unfiltered > 0) + routes.pending = [] } if (filter === undefined && ++routes.unfiltered >= FILTER_AFTER) { @@ -359,16 +363,6 @@ function indexStatics(routes: MethodRoutes): void { routes.indexed = indexed } -/** - * Adds the routes in `pending` to the tree. Once the tree has served a - * request, each goes in whole, as routes may no longer wait where the tree - * has grown past them. - */ -function build(routes: MethodRoutes): void { - expand(routes.root, routes.pending, 1, routes.unfiltered > 0) - routes.pending = [] -} - /** * Adds the routes waiting at `node`, which is at `start` in the split path, to * the tree, in one loop rather than a call per route, which V8 would see as