Skip to content


Subversion checkout URL

You can clone with
Download ZIP


[Routing] optimize static requirement on compile #6838

Tobion opened this Issue · 9 comments

5 participants


I sometimes see route definitions like the following where a requirement for a variable is no real regex but static text:

    path: /export.{_format}
    defaults: { _controller: "Acme:Action:export" }
        _format: csv

This is equivalent to

    path: /export.csv
    defaults: { _controller: "Acme:Action:export", _format: csv }

It can be optimized at compile time and would safe subpattern or even a complete regex match as in this case because the path is static now.
I already know how to implement this. This is just a reminder for me. ^^
Use if (preg_quote($requirement) === $requirement) for detection.


Oh damnit, it is equivalent for matching but unfortunately not for generating a URL as a _format parameter would become a query param then. Hm, let's see.

If it's not possible to do on compile securely, it can be done at least at dumping the matcher.


@Tobion If I were to pickup on this would you guide me thru it? I know you said you know how to do it but I'd rather implement it so I can better understand the new routing component better.


@Tobion this optimization could be done exclusively by the MatcherDumper.


Actually, I think this optimization can be done by the RouteCompiler: the generator does not use the compiled regex pattern. Keeping the parameter in the compiled route variables will keep it away from the query string thanks to


hmm, actually, I see 1 issue with this: the param would still be required because of the comparison with route variable but would be omitted because it matches the default added in the route, thus generating a different url.
It would work after fixing #5180


@stof indeed, it would be better to let the RouteCompiler perform this optimization. I was not aware of #5180, I'll try to ptopose a PR for it, and close #8497 in favaor of a RouteCompiler patch.


@jfsimon there is already an old PR for it, but the issue is BC.


@stof the more I read comments from #5410 the more I doubt it's fixeable :(


Looks like a lot of additional code for a very slight benefit. Closing.

@fabpot fabpot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.