Skip to content

[Routing] Transform dynamic routes with static path variables to static routes #35821

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

Conversation

mtarld
Copy link
Contributor

@mtarld mtarld commented Feb 21, 2020

Q A
Branch? master
Bug fix? no
New feature? no
Deprecations? no
License MIT

Implementation of idea mentioned here: #35735 (review)

Improve route matching performances by turning dynamic routes with static path variables to actual static routes.

To do if implementation is accepted

  • Write tests

@mtarld mtarld force-pushed the feature/static-routes-improvements branch from 6517cc7 to 8f70316 Compare February 22, 2020 14:12
@mtarld mtarld changed the title [Routing] Transform dynamic routes with fixed path variables to static routes [Routing] Transform dynamic routes with static path variables to static routes Feb 22, 2020
@mtarld mtarld marked this pull request as ready for review February 22, 2020 14:15
@nicolas-grekas nicolas-grekas added this to the next milestone Feb 23, 2020
* @return CompiledRoute A CompiledRoute instance
*
* @throws \LogicException If the Route cannot be compiled because the
* path or host pattern is invalid
*
* @see RouteCompiler which is responsible for the compilation process
*/
public function compile()
public function compile(bool $forGenerator = false)
Copy link
Member

@nicolas-grekas nicolas-grekas Feb 23, 2020

Choose a reason for hiding this comment

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

I'm not sure to get why we need a different compilation result for generator vs dumper?
If we really need this, then I would prefer to deal with the optimization inside the dumper, so that no public API needs to change.
This should remain an internal implementation detail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it's unclear but I meant compiling differently for matching vs generation.
Generation shouldn't be modified because of strictRequirements and stuff. Therefore in fact I made a mistake, $forGeneration should instead be $forMatching.
I would rather as well keeping implementation inside the dumper.
I'll try another approach thanks

@@ -184,6 +186,12 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo
$regexp = self::transformCapturingGroupsToNonCapturings($regexp);
}

// Fixed variable, could be transformed as text token
if ($fixStaticVariables && preg_quote($regexp, self::REGEX_DELIMITER) === $regexp) {
Copy link
Member

Choose a reason for hiding this comment

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

does this really work?
if the static data is a.b, $regexp will be a\.b:

  • preg_quote($regexp, self::REGEX_DELIMITER) => a\\\.b !== $regexp

Instead, we should do preg_quote(unpreg_quote($regexp), self::REGEX_DELIMITER) === $regexp - with unpreg_quote() to be written.

@@ -198,6 +206,10 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo
$tokens[] = ['text', substr($pattern, $pos)];
}

if ($fixStaticVariables) {
$tokens = self::mergeContiguousTextTokens($tokens);
Copy link
Member

Choose a reason for hiding this comment

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

Thre is a critical thing missing: the static value must be set as the default of the corresponding attribute.
Please add a few test cases that cover the need.

@mtarld
Copy link
Contributor Author

mtarld commented Feb 24, 2020

As we found a better approach, I close that PR

@mtarld mtarld closed this Feb 24, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants