Skip to content

perf(routing): dispatch frontend routes through a compiled matcher - #28

Merged
brianvarskonst merged 2 commits into
mainfrom
perf/compiled-frontend-router
Oct 23, 2026
Merged

brianvarskonst merged 2 commits into
mainfrom
perf/compiled-frontend-router

Conversation

@brianvarskonst

Copy link
Copy Markdown
Member

Finding

Review finding K-P6: RouteLoader::handle() created a UrlMatcher over the RouteCollection on every frontend request, matching one regular expression per route. The cost grows linearly with the number of attribute routes.

Change

  • RouteLoader::compileRoutes() builds the CompiledUrlMatcherDumper tables (static prefix tree, merged regular expressions) at container compile time; RouteCompilerPass stores them as the fourth RouteLoader argument so they are part of the dumped container.
  • handle() uses CompiledUrlMatcher when tables exist and falls back to the previous UrlMatcher otherwise.
  • Routes with a condition keep the runtime matcher: their check compiles to a closure that cannot be dumped. An empty route list compiles to nothing.
  • The core registrar passes the new default argument; the constructor parameter is trailing and optional, so existing callers are unaffected.

Verification

  • RouteAttributeTest asserts that the fixture container carries compiled tables and still matches, returns 405 with Allow, and that conditional/empty route lists compile to [].
  • Routing, contract and console suites pass; composer cs and composer static-analysis pass in a PHP 8.5.12 container.

brianvarskonst and others added 2 commits October 23, 2026 23:50
RouteLoader built a UrlMatcher per request and tested one regular expression per
route. The compiler pass now dumps the CompiledUrlMatcherDumper tables into the
container so warm requests use CompiledUrlMatcher. Routes with a condition keep
the runtime matcher because their check compiles to a closure.
@brianvarskonst
brianvarskonst merged commit 3474b02 into main Oct 23, 2026
3 checks passed
@brianvarskonst
brianvarskonst deleted the perf/compiled-frontend-router branch October 23, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant