[26.0] Cache url path lookup#22198
Open
mvdbeek wants to merge 2 commits intogalaxyproject:release_26.0from
Open
[26.0] Cache url path lookup#22198mvdbeek wants to merge 2 commits intogalaxyproject:release_26.0from
mvdbeek wants to merge 2 commits intogalaxyproject:release_26.0from
Conversation
I've seen py-spy dumps where usegalaxy.org was busy looking up routes. This is an easy win. Claude claims 87X speedup in a synthetic benchmark: https://gist.github.com/mvdbeek/a257c8885edba9e02482b598076eaa0e
nsoranzo
reviewed
Mar 20, 2026
Comment on lines
+244
to
+245
| url = route.url_path_for(name, **path_params) | ||
| self._route_cache[name] = route |
Member
There was a problem hiding this comment.
After reading https://github.com/Kludex/starlette/blob/main/starlette/routing.py , I think that this is not 100% safe, as there could be multiple routes with the same name and only one match with the specified path_params , so reusing the cached value for different path_params may be incorrect.
Multiple routes can share a name but expect different parameter sets. Using just the name as cache key could return the wrong route when path_params differ. Key on (name, frozenset(path_params)) instead.
70317f2 to
261634b
Compare
This file contains hidden or 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
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.
I've seen py-spy dumps where usegalaxy.org was busy looking up routes. This seems like an easy win. Claude claims 87X speedup in a synthetic benchmark: https://gist.github.com/mvdbeek/a257c8885edba9e02482b598076eaa0e
How to test the changes?
(Select all options that apply)
License