Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Routing] check static routes first in a switch#25961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedJan 29, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PR-

Improves performance by moving static routes first when possible. Should benefit PHP 7.2 most, where switch uses a hash table.
Embeds a few fixes for bugs found meanwhile, which I'm going to submit separately for lower branches (see#25962.)

linaori and apfelbox reacted with thumbs up emoji
@javiereguiluz
Copy link
Member

Can anyone please benchmark this change with a non-trivial set of routes and using PHP 7.2? Thanks!

@nicolas-grekasnicolas-grekasforce-pushed therouter-static branch 2 times, most recently from896e5e9 tofd00c81CompareFebruary 4, 2018 13:13
@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedFeb 4, 2018
edited
Loading

The perf improvement is significant: for 400 static + 400 dynamic routes, matching the last static route

  • when the 400 static precede the others: 72ms vs 65 ms for 10k match()
  • when the routes are interweaved: 775ms vs 65ms

@derrabus
Copy link
Member

So, this basically changes the order of the routes, doesn't it? Could this be a problem?

@nicolas-grekas
Copy link
MemberAuthor

@derrabus not if done wisely, which should be the case here - at least there is some logic to ensure this should not be an issue. Please review :)

@nicolas-grekas
Copy link
MemberAuthor

Closing in favor of#26059

@nicolas-grekasnicolas-grekas deleted the router-static branchFebruary 6, 2018 07:25
Tobion added a commit that referenced this pull requestFeb 12, 2018
…e regexp (nicolas-grekas)This PR was merged into the 4.1-dev branch.Discussion---------- [Routing] Match 77.7x faster by compiling routes in one regexp| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -Builds on top of#25961 andhttp://nikic.github.io/2014/02/18/Fast-request-routing-using-regular-expressions.html to make routing 77.7x faster (measured when matching the last dynamic route of 400 static + 400 dynamic routes.)More benchs welcomed.- [x] check static routes first in a switch- [x] group same-modifiers regexps- [x] put condition-less routes in a static map, in a switch's "default"- [x] match host+pathinfo at the same time- [x] group same-host regexps in sub-patterns- [x] consider the host to move more static routes in the static switch- [x] move static single-route "case" to "default" by adding requirements to $routes- [x] group same-static-prefix in sub-patterns- [x] group consecutive same-regex in a single "case"- [x] move dynamic single-route "case" to "default" by adding requirements to $routes- [x] extract host variables from the main match and remove the current 2nd match- [x] extend same-prefix grouping to placeholders- [x] group same-suffix hosts togetherHere is my benchmarking code:```php<?phpnamespace Symfony\Component\Routing;require 'vendor/autoload.php';$routes = new RouteCollection();for ($i = 0; $i < 400; ++$i) {    $routes->add('r'.$i, new Route('/abc'.$i));    $routes->add('f'.$i, new Route('/abc{foo}/'.$i));}$dumper = new Matcher\Dumper\PhpMatcherDumper($routes);eval('?'.'>'.$dumper->dump());$router = new \ProjectUrlMatcher(new RequestContext());$i = 10000;$s = microtime(1);while (--$i) {    $router->match('/abcdef/399');}echo 'Symfony: ', 1000 * (microtime(1) - $s), "\n";namespace FastRoute;$dispatcher = simpleDispatcher(function(RouteCollector $r) {    for ($i = 0; $i < 400; ++$i) {        $r->addRoute('GET', '/abc'.$i, 'r'.$i);        $r->addRoute('GET', '/abc{foo}/'.$i, 'f'.$i);    }});$i = 10000;$s = microtime(1);while (--$i) {    $dispatcher->dispatch('GET', '/abcdef/399');}echo 'FastRoute: ', 1000 * (microtime(1) - $s), "\n";```Commits-------f933f70 [Routing] Match 77.7x faster by compiling routes in one regexp
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

4 participants

@nicolas-grekas@javiereguiluz@derrabus@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp