-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Persist routes indexed by name in RouteCollector for improved performance. #3235
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Buster Neece <buster@busterneece.com>
akrabat
requested changes
Nov 5, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! Just a few changes that would be useful.
@akrabat Changes should be incorporated now. |
Don't output the tip to the log.
These tests aren't testing the log output, so they just clutter up the PHPUnit output for no reason.
akrabat
approved these changes
Nov 6, 2022
Thanks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In our application, we have what I think is a reasonable number of routes defined (a few dozen), and we're often calling
RouteParserInterface::relativeUrlFor
and its related functions. Under the hood, these all callRouteCollectorInterface::getNamedRoute
, and right now, that's iterating through every single route, checking the name, and returning the result if it finds it.Individually, these calls aren't a big deal, but they add up fast. If, say, you're returning an API response with several records with several links in each row, this tends to result in a huge number of calls to
RouteInterface::getName()
.As a result of their exposed methods, the nature of the
RouteCollectorInterface
andRouteParserInterface
means that it isn't possible to implement a lookup table like this in one's own code without reimplementing the entireRouteParserInterface::relativeUrlFor
functionality.However, fortunately that also means that this change can be made at the Slim level without any change to the interface. The logic here is identical to how it functions currently (the first route with a given name is returned by
getNamedRoute()
).