Skip to content

v12.56.0

@SanderMuller SanderMuller tagged this 16 Mar 14:15
When using cached routes (route:cache), getByName() constructs a new
Route object from the compiled attributes array on every call. This
involves Router::newRoute(), setFallback(), setDefaults(), setWheres(),
setBindingFields(), block(), and withTrashed() — repeated work for the
same route.

This is called on every request during route matching (match() calls
getByName()), and on every route() URL generation call in Blade
templates. A typical page with 20-50 route() calls in the navigation
rebuilds the same Route objects repeatedly.

Caching the constructed Route by name eliminates this redundancy:

  getByName:  26.3ms → 0.5ms per 10K calls (-98%)
  route():    85.6ms → 50.4ms per 10K calls (-41%)
  match():   176.0ms → 82.8ms per 10K calls (-53%)
Assets 2
Loading