8000 [Routing] Optimised dumped router matcher, prevent unneeded function calls. by frankdejonge · Pull Request #21755 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing] Optimised dumped router matcher, prevent unneeded function calls. #21755

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Prev Previous commit
Next Next commit
After filtering there's also a case where only one HTTP method is pre…
…sent.
  • Loading branch information
frankdejonge committed Feb 27, 2017
commit 44271e07e1e22650335abd15ceb434c627330ce3
15 changes: 13 additions & 2 deletions src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php
Original file line number Diff line number Diff line change
Expand Up @ 8000 @ -296,15 +296,26 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
$methods = array_filter($methods, function ($method) { return 'HEAD' !== $method; });
}

$methods = implode("', '", $methods);
$code .= <<<EOF
if (1 === count($methods)) {
$code .= <<<EOF
if ('$methods[0]' !== \$$methodVariable) {
\$allow[] = '$methods[0]';
goto $gotoname;
Copy link
Contributor
@GuilhemN GuilhemN Feb 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has the use of the goto ever been discussed?
It seems like here we only need to reverse the conditions to get ride of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm checking this out now, if proven to be effective I'll create another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GuilhemN I suspected it to have some effect, but it did literally nothing.

}


EOF;
} else {
$methods = implode("', '", $methods);
$code .= <<<EOF
if (!in_array(\$$methodVariable, array('$methods'))) {
\$allow = array_merge(\$allow, array('$methods'));
goto $gotoname;
}


EOF;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function match($pathinfo)
if (0 === strpos($pathinfo, '/bar')) {
// bar
if (preg_match('#^/bar/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if (!in_array($isLikeGetMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
if ('GET' !== $isLikeGetMethod) {
$allow[] = 'GET';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't you adding HEAD anymore here ? It is an allowed method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof this was an optimisation proposed by @fabpot. We stream HEAD in a special way (this is current behaviour). When a HEAD request is made, we also match GET. Inverted, when we declare GET actions, we also match in HEAD. So in this normalised case we know that if something is "like get" we don't need HEAD anymore because we're we already match GET.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make sure that this is properly tested? If someone else breaks this, it will be a huge bug!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jean85 there's an additional test case added in this PR to do just that.

goto not_bar;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function match($pathinfo)
if (0 === strpos($pathinfo, '/bar')) {
// bar
if (preg_match('#^/bar/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if (!in_array($isLikeGetMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
if ('GET' !== $isLikeGetMethod) {
$allow[] = 'GET';
goto not_bar;
}

Expand Down
0