[PR #396] [MERGED] perf: pre-split route patterns and hoist URL split out of match loop #540

Closed
opened 2026-05-06 13:08:39 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/396
Author: @NathanDrake2406
Created: 3/10/2026
Status: Merged
Merged: 3/10/2026
Merged by: @james-elicx

Base: mainHead: perf/route-match-presplit


📝 Commits (3)

  • 68e9402 perf: pre-split route patterns and hoist URL split out of match loop
  • 6c9d5db Merge remote-tracking branch 'origin/main' into perf/route-match-presplit
  • 8b48a14 update entry-templates snapshots

📊 Changes

9 files changed (+144 additions, -93 deletions)

View changed files

📝 packages/vinext/src/entries/app-rsc-entry.ts (+7 -5)
📝 packages/vinext/src/entries/pages-server-entry.ts (+5 -6)
📝 packages/vinext/src/routing/app-router.ts (+12 -5)
📝 packages/vinext/src/routing/pages-router.ts (+11 -5)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+100 -71)
📝 tests/api-handler.test.ts (+1 -1)
📝 tests/app-router.test.ts (+2 -0)
📝 tests/entry-templates.test.ts (+4 -0)
📝 tests/shims.test.ts (+2 -0)

📄 Description

Summary

  • Route matching (matchPattern) was re-splitting both the URL and pattern strings on every loop iteration. For N routes checked before a match, that's N redundant url.split("/") calls (same URL every time) + N pattern.split("/") calls (patterns are static after scan)
  • Add patternParts: string[] to Route and AppRoute interfaces, computed once at filesystem scan time
  • Split the URL once in matchRoute/matchAppRoute before the loop, pass pre-split arrays to matchPattern
  • Applied to all 4 implementations: runtime pages-router, runtime app-router, generated pages-server-entry, generated app-rsc-entry
  • Fixed intercepting route lookup (findIntercept) to use the new array-based API

Test plan

  • 917 tests passing across routing, app-router, api-handler, entry-templates, and shims test files
  • Intercepting route test specifically verified (was broken, fixed)
  • Typecheck clean
  • Lint clean
  • Snapshots updated

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/396 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/10/2026 **Status:** ✅ Merged **Merged:** 3/10/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `perf/route-match-presplit` --- ### 📝 Commits (3) - [`68e9402`](https://github.com/cloudflare/vinext/commit/68e9402968972876f4912e51bedba9d1b8b3ac69) perf: pre-split route patterns and hoist URL split out of match loop - [`6c9d5db`](https://github.com/cloudflare/vinext/commit/6c9d5dbd997de0c462e80c45e8951500ca1e91f1) Merge remote-tracking branch 'origin/main' into perf/route-match-presplit - [`8b48a14`](https://github.com/cloudflare/vinext/commit/8b48a143768a79c0ca1655e298b43929c1ef5bda) update entry-templates snapshots ### 📊 Changes **9 files changed** (+144 additions, -93 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/app-rsc-entry.ts` (+7 -5) 📝 `packages/vinext/src/entries/pages-server-entry.ts` (+5 -6) 📝 `packages/vinext/src/routing/app-router.ts` (+12 -5) 📝 `packages/vinext/src/routing/pages-router.ts` (+11 -5) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+100 -71) 📝 `tests/api-handler.test.ts` (+1 -1) 📝 `tests/app-router.test.ts` (+2 -0) 📝 `tests/entry-templates.test.ts` (+4 -0) 📝 `tests/shims.test.ts` (+2 -0) </details> ### 📄 Description ## Summary - Route matching (`matchPattern`) was re-splitting both the URL and pattern strings on every loop iteration. For N routes checked before a match, that's N redundant `url.split("/")` calls (same URL every time) + N `pattern.split("/")` calls (patterns are static after scan) - Add `patternParts: string[]` to `Route` and `AppRoute` interfaces, computed once at filesystem scan time - Split the URL once in `matchRoute`/`matchAppRoute` before the loop, pass pre-split arrays to `matchPattern` - Applied to all 4 implementations: runtime pages-router, runtime app-router, generated pages-server-entry, generated app-rsc-entry - Fixed intercepting route lookup (`findIntercept`) to use the new array-based API ## Test plan - [x] 917 tests passing across routing, app-router, api-handler, entry-templates, and shims test files - [x] Intercepting route test specifically verified (was broken, fixed) - [x] Typecheck clean - [x] Lint clean - [x] Snapshots updated --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:08:39 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#540
No description provided.