mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #395] [MERGED] perf: cache compiled regexes in middleware matcher #539
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#539
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?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/395
Author: @NathanDrake2406
Created: 3/10/2026
Status: ✅ Merged
Merged: 3/10/2026
Merged by: @james-elicx
Base:
main← Head:fix/middleware-regex-cache📝 Commits (1)
fb52807perf: cache compiled regexes in middleware matcher📊 Changes
3 files changed (+67 additions, -37 deletions)
View changed files
📝
packages/vinext/src/server/middleware-codegen.ts(+12 -10)📝
packages/vinext/src/server/middleware.ts(+31 -7)📝
tests/__snapshots__/entry-templates.test.ts.snap(+24 -20)📄 Description
Summary
config.matcher) are static butmatchPattern()was re-running the full tokeniser +isSafeRegexscan +new RegExp()on every request for every matcher entryconfig-matchers.tssolved with_compiledPatternCache(which eliminated ~2.4s of CPU self-time in profiling) — the middleware path was never given the same fixMap<string, RegExp | null>cache to both the runtimematchPattern()and the codegenmatchMiddlewarePattern()so each pattern is compiled exactly once per process lifetimeTest plan
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.