From 1b30f15c02cb9d2406e9ab9fa027c8a03b35619d Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Mon, 12 Oct 2026 14:27:24 -0500 Subject: [PATCH] perf(router): reset the walk stack only when a lookup throws The finally block added in a2b71e2 wrote both stacks' length on every lookup, which drops their backing storage and made every walked lookup pay for reallocation: +50% late param hit, +33% method miss and +104% path miss at 10 routes on jarvis (CARD-10). A normal walk already ends at base, so reset only in a catch and rethrow. Signed-off-by: Diego Resendez --- src/http/router.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/http/router.ts b/src/http/router.ts index 55173c4..379e1a3 100644 --- a/src/http/router.ts +++ b/src/http/router.ts @@ -612,10 +612,13 @@ function walk(root: RadixNode, search: Search, segs: string[]): void { stackDepths.push(depth + 1); } } - } finally { + } catch (error) { // A malformed `%` escape throws out of `decodeSegment` with frames still pending; drop them. + // Not in a `finally`: a normal walk already ends at `base`, and writing `length` on every lookup + // drops the arrays' storage, which cost D4 at 10 routes (FPRD-001 CARD-10). stackNodes.length = base; stackDepths.length = base; + throw error; } } -- 2.54.1