perf: fast-path interception route check and cache bot-detection regex#91594
Open
benfavre wants to merge 1 commit intovercel:canaryfrom
Open
perf: fast-path interception route check and cache bot-detection regex#91594benfavre wants to merge 1 commit intovercel:canaryfrom
benfavre wants to merge 1 commit intovercel:canaryfrom
Conversation
Two targeted optimizations from CPU profile hotspots:
1. `isInterceptionRouteAppPath` (37ms): Add early return for paths without
parentheses. Interception markers all start with `(`, so a simple
`path.includes('(')` check skips the `.split('/') + .find()` work for
the vast majority of routes that aren't interception routes.
2. `shouldServeStreamingMetadata` (31ms): Cache the compiled RegExp for the
HTML-limited bot UA pattern. The pattern comes from static config
(`nextConfig.htmlLimitedBots`) and never changes between requests, but
`new RegExp()` was being called on every request.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
Contributor
Author
CPU Profile Verification
The |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two targeted optimizations from CPU profile hotspots:
isInterceptionRouteAppPath(~37ms): Added an early return for paths that don't contain(. All interception route markers ((.),(..),(...),(..)(..)) start with a parenthesis, so a cheappath.includes('(')pre-check avoids the.split('/') + nested .find()for the vast majority of non-interception routes.shouldServeStreamingMetadata(~31ms): Cached the compiledRegExpfor the HTML-limited bot UA pattern. The pattern comes from static config (nextConfig.htmlLimitedBots) and never changes between requests, butnew RegExp(...)was being constructed on every single request.Both changes are zero-risk: the first adds a pre-check that's logically equivalent (no parenthesis means no marker can match), and the second caches a regex that was being identically reconstructed each time.
Test plan
interception-routes.test.tsunit tests pass (verified locally with inline logic tests — true/false cases including route groups with parens, plain paths, and all 4 interception markers)false, normal UAs still returntrue, customhtmlLimitedBotsconfig still works🤖 Generated with Claude Code