SymfonyWorld Online 2021 Winter Edition December 9 – 10, 2021 100% Online +20 talks and workshops

New in Symfony 3.3: Faster routing

Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.

Contributed by
Frank de Jonge
in #21755 and #21926.

The Symfony Routing component is one of the most critical pieces of any Symfony application. First, because it's used to generate the URLs of links in your templates (that's the "URL generator" part) and second, because it decides which code to execute to respond to any given request (that's the "URL matcher" part).

Moreover, it must be blazing fast to not hurt the application performance. Instead of checking all the application routes whenever a URL is generated or matched, the component parses this configuration once and dumps the result as two big PHP files optimized for URL generating or matching. You can find those files called *UrlGenerator.php and *UrlMatcher.php in the cache of your application.

Even if those files have been meticulously optimized during the past years, there's always more room for improvements. In Symfony 3.3 we added a lot of micro-optimizations to generate better dump files that result in less function calls during the application execution.

In practice, these changes will be mostly noticed by applications with lots of routes. For example, in a sample application with 900 routes, the URL matching process went from 7.5ms to 2.5ms. In smaller applications, you'll see minor differences, but every millisecond counts when making your applications faster!

If you are curious, you can see the PR 21755 and PR 21926 for the full details about those changes. Check out also this blog post published by Frank where he explains how he did it.

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.


Good work, thanks for every optimization!!!
Good job thanks
Nice job, optimizations in the Routing components are always welcome :)
Are there any detailed statistics on how big the savings are?

I am especially interested in savings regarding changing greedy regular expressions to possessive ones. I am referring to the comment @stof made on the original blog post.

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.