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
Renamed isLikeGetMethod to canonicalMethod.
  • Loading branch information
frankdejonge committed Feb 28, 2017
commit bb68154c5e432146cb50c73a67b3ee0617f1a3c0
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ public function match(\$pathinfo)
\$trimmedPathinfo = rtrim(\$pathinfo, '/');
\$context = \$this->context;
\$request = \$this->request;
\$requestMethod = \$isLikeGetMethod = \$context->getMethod();
\$requestMethod = \$canonicalMethod = \$context->getMethod();
\$schema = \$context->getScheme();
Copy link
Member

Choose a reason for hiding this comment

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

should be $scheme here, not $schema, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabpot correct, I've fixed it.


if ('HEAD' === \$requestMethod) {
\$isLikeGetMethod = 'GET';
\$canonicalMethod = 'GET';
}


Expand Down Expand Up @@ -280,7 +280,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
EOF;
} else {
$code .= <<<EOF
if ('$methods[0]' !== \$isLikeGetMethod) {
if ('$methods[0]' !== \$canonicalMethod) {
\$allow[] = '$methods[0]';
goto $gotoname;
}
Expand All @@ -293,7 +293,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren

if (in_array('GET', $methods)) {
// Since we treat HEAD requests like GET requests we don't need to match it.
$methodVariable = 'isLikeGetMethod';
$methodVariable = 'canonicalMethod';
$methods = array_filter($methods, function ($method) { return 'HEAD' !== $method; });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function match($pathinfo)
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$request = $this->request;
$requestMethod = $isLikeGetMethod = $context->getMethod();
$requestMethod = $canonicalMethod = $context->getMethod();
$schema = $context->getScheme();

if ('HEAD' === $requestMethod) {
$isLikeGetMethod = 'GET';
$canonicalMethod = 'GET';
}


Expand All @@ -43,7 +43,7 @@ public function match($pathinfo)
if (0 === strpos($pathinfo, '/bar')) {
// bar
if (preg_match('#^/bar/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if ('GET' !== $isLikeGetMethod) {
if ('GET' !== $canonicalMethod) {
$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 All @@ -54,7 +54,7 @@ public function match($pathinfo)

// barhead
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if ('GET' !== $isLikeGetMethod) {
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
goto not_barhead;
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public function match($pathinfo)

// baz5
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
if ('POST' !== $isLikeGetMethod) {
if ('POST' !== $canonicalMethod) {
$allow[] = 'POST';
goto not_baz5;
}
Expand All @@ -102,7 +102,7 @@ public function match($pathinfo)

// baz.baz6
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
if ('PUT' !== $isLikeGetMethod) {
if ('PUT' !== $canonicalMethod) {
$allow[] = 'PUT';
goto not_bazbaz6;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function match($pathinfo)
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$request = $this->request;
$requestMethod = $isLikeGetMethod = $context->getMethod();
$requestMethod = $canonicalMethod = $context->getMethod();
$schema = $context->getScheme();

if ('HEAD' === $requestMethod) {
$isLikeGetMethod = 'GET';
$canonicalMethod = 'GET';
}


Expand All @@ -43,7 +43,7 @@ public function match($pathinfo)
if (0 === strpos($pathinfo, '/bar')) {
// bar
if (preg_match('#^/bar/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if ('GET' !== $isLikeGetMethod) {
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
goto not_bar;
}
Expand All @@ -54,7 +54,7 @@ public function match($pathinfo)

// barhead
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if ('GET' !== $isLikeGetMethod) {
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
goto not_barhead;
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public function match($pathinfo)

// baz5
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
if ('POST' !== $isLikeGetMethod) {
if ('POST' !== $canonicalMethod) {
$allow[] = 'POST';
goto not_baz5;
}
Expand All @@ -110,7 +110,7 @@ public function match($pathinfo)

// baz.baz6
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
if ('PUT' !== $isLikeGetMethod) {
if ('PUT' !== $canonicalMethod) {
$allow[] = 'PUT';
goto not_bazbaz6;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function match($pathinfo)
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$request = $this->request;
$requestMethod = $isLikeGetMethod = $context->getMethod();
$requestMethod = $canonicalMethod = $context->getMethod();
$schema = $context->getScheme();

if ('HEAD' === $requestMethod) {
$isLikeGetMethod = 'GET';
$canonicalMethod = 'GET';
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function match($pathinfo)
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$request = $this->request;
$requestMethod = $isLikeGetMethod = $context->getMethod();
$requestMethod = $canonicalMethod = $context->getMethod();
$schema = $context->getScheme();

if ('HEAD' === $requestMethod) {
$isLikeGetMethod = 'GET';
$canonicalMethod = 'GET';
}


Expand All @@ -48,7 +48,7 @@ public function match($pathinfo)

// head_and_get
if ('/head_and_get' === $pathinfo) {
if ('GET' !== $isLikeGetMethod) {
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
goto not_head_and_get;
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public function match($pathinfo)

// put_and_get_and_head
if ('/put_and_post' === $pathinfo) {
if (!in_array($isLikeGetMethod, array('PUT', 'GET'))) {
if (!in_array($canonicalMethod, array('PUT', 'GET'))) {
$allow = array_merge($allow, array('PUT', 'GET'));
goto not_put_and_get_and_head;
}
Expand Down
0