mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #444] perf: replace O(n) linear route matching with radix trie #100
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#100
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Divkix on GitHub (Mar 11, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/444
Problem
Every incoming request triggers 3-6 linear scans over the full route list, calling
matchPattern(urlParts, route.patternParts)for every route until a match. For apps with 500 routes this means 1,500-3,000 pattern comparisons per request.The matching logic is duplicated in 4 codebases:
pages-router.ts(scanner module, dev time)app-router.ts(scanner module, dev time)app-rsc-entry.ts(generated entry, runtime)pages-server-entry.ts(generated entry, runtime)Solution
Replace the linear scan with a radix trie that provides O(depth) lookup instead of O(n). The trie enforces correct precedence via traversal order at each node (static > dynamic > catch-all > optional catch-all) with recursive DFS backtracking for dead-end branches.
Implementation
[plugin rsc:use-client] unsupported ExportAllDeclaration#182