This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Routing
Fabien Potencier 940c29abec minor #21926 [Routing] Optimised dumped matcher (frankdejonge)
This PR was squashed before being merged into the 3.3-dev branch (closes #21926).

Discussion
----------

[Routing] Optimised dumped matcher

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

TL;DR: I've optimised the PhpMatcherDumper output for a <del>60x</del> 4.4x performance improvement on a collection of ~800 routes by inducing cyclomatic complexity.

[EDIT] The 60x performance boost was only visible when profiling with blackfire, which is quite possibly a result of the cost of profiling playing a part. After doing some more profiling the realistic benefit of the optimisation is more likely to be in the ranges is 1.3x to 4.4x.

After the previous optimisation I began looking at how the PrefixCollection was adding its performance boost. I spotted another way to do this, which has the same theory behind it (excluding groups based on prefixes). The current implementation only groups when one prefix resides in the other. In this new implementation I've created a way to detect common prefixes, which allows for much more efficient grouping. Every time a route is added to the group it'll either merge into an existing group, merge into a new group with a route that has a common prefix, or merge into a new group with an existing group that has a common prefix.

However, when a parameter is present grouping must only be done AFTER that route, this case is accounted for. In all other cases, where there's no collision routes can be grouped freely because if a group was matched other groups wouldn't have matched.

After all the groups are created the groups are optimised. Groups with fewer than 3 children are inlined into the parent group. This is because a group with 2 children would potentially result in 3 prefix checks while if they are inlines it's 2 checks.

Like with the previous optimisation I've profiled this using blackfire. But the match function didn't show up anymore. I've added `usleep` calls in the dumped matcher during profiling, which made it show up again. I've verified with @simensen that this is because the wall time of the function was too small for it to be of any interest. When it DID get detected, because of more tasks running, it would show up with around 250 nanoseconds. In comparison, the previous speed improvement brought the wall time down from 7ms to ~2.5ms on a set of ~800 routes.

Because of the altered grouping behaviour I've not modified the PrefixCollection but I've created a new StaticPrefixCollection and updated the PhpMatcherDumper to use that instead.

Commits
-------

449b6912dc [Routing] Optimised dumped matcher
2017-03-22 12:45:31 -07:00
..
Annotation Merge branch '2.8' into 3.0 2016-06-29 07:40:00 +02:00
DependencyInjection Move RoutingResolverPass to the Routing component 2017-03-05 16:12:05 +01:00
Exception remove api tags from code 2015-09-28 19:11:22 +02:00
Generator [Routing] Fixed route generation with fragment defined as defaults 2016-09-21 17:48:58 +03:00
Loader [DoctrineBridge][Routing] Require PSR-11 container instead of Symfony container 2017-03-12 08:32:31 -07:00
Matcher [Routing] Optimised dumped matcher 2017-03-22 12:45:25 -07:00
Tests [Routing] Optimised dumped matcher 2017-03-22 12:45:25 -07:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
CHANGELOG.md Add deprecation note on routing class parameters 2017-03-01 21:50:23 +01:00
CompiledRoute.php Conditionally add options to unserialize in PHP 7.0+. 2016-12-29 19:41:55 +01:00
composer.json [DoctrineBridge][Routing] Require PSR-11 container instead of Symfony container 2017-03-12 08:32:31 -07:00
LICENSE updated LICENSE year 2017-01-02 12:30:00 -08:00
phpunit.xml.dist Add missing exclusions from phpunit.xml.dist 2015-11-18 09:19:46 +01:00
README.md Updated all the README files 2016-03-04 08:12:06 +01:00
RequestContext.php fixed @return when returning this or static 2016-12-27 08:23:47 +01:00
RequestContextAwareInterface.php remove api tags from code 2015-09-28 19:11:22 +02:00
Route.php minor #21090 Secure unserialize by restricting allowed classes when using PHP 7 (dbrumann) 2017-02-12 20:14:59 +01:00
RouteCollection.php add docblock type elements to support newly added IteratorAggregate::getIterator PhpStorm support 2016-06-17 14:42:34 +02:00
RouteCollectionBuilder.php added support for glob loaders in Config 2017-02-18 08:06:39 -08:00
RouteCompiler.php [Routing] Optimised dumped matcher 2017-03-22 12:45:25 -07:00
RouteCompilerInterface.php renamed hostname to host in the routing system (closes #6775) 2013-01-21 17:57:32 +01:00
Router.php Merge branch '2.8' into 3.1 2016-08-16 07:58:24 -07:00
RouterInterface.php

Routing Component

The Routing component maps an HTTP request to a set of configuration variables.

Resources