demo
                                
                                 demo copied to clipboard
                                
                                    demo copied to clipboard
                            
                            
                            
                        Use possessive quantifiers in routing requirements?
As @stof explained in #817:
I suggest using a possessive quantifier to improve the route matching performance (Symfony generates possessive quantifiers for its builtin requirements, but custom ones need to do that themselves, as using non-possessive quantifiers can still be a valid use case)
He's technically right, but we need to decide if we do that in this Demo app or not:
// BEFORE
@Route("/{id<\d+>}/edit",methods={"GET", "POST"}, name="admin_post_edit")
@Route("/page/{page<[1-9]\d*>}", defaults={"_format"="html"}, methods={"GET"}, name="blog_index_paginated")
// AFTER
@Route("/{id<\d++>}/edit",methods={"GET", "POST"}, name="admin_post_edit")
@Route("/page/{page<[1-9]\d*+>}", defaults={"_format"="html"}, methods={"GET"}, name="blog_index_paginated")
Some pros and cons:
- (Con) This is a Demo app not a benchmark app, so clarity is preferred over speed.
- (Con) The \d++and\d*+can confuse lots of developers who don't know regexp well
- (Pro) Using these can be a good opportunity to help teach about them.
- (Pro) It makes the routing slightly faster
- ...
another pro: it demos the faster practice, so users may use it in their own projects too (which probably wants performance as it would not be a demo)
Let's close this as "won't fix". I still think that the potential confusion of doing this change is much bigger than the small performance improvement. Thanks for understanding.