-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[PR #7829/2a3eaa11 backport][3.10] Index resources in the UrlDispatcher to avoid linear search for most cases #7917
Conversation
@bdraco Looks like something went bad in the backport, tests are failing and taking forever... |
I'll take a look as soon as I can |
diff --git a/aiohttp/web_urldispatcher.py b/aiohttp/web_urldispatcher.py
index d13ccfbf..a2cc6563 100644
--- a/aiohttp/web_urldispatcher.py
+++ b/aiohttp/web_urldispatcher.py
@@ -1048,7 +1048,7 @@ class UrlDispatcher(AbstractRouter, Mapping[str, AbstractResource]):
if allowed_methods:
return MatchInfoError(HTTPMethodNotAllowed(request.method, allowed_methods))
- return MatchInfoError(self.HTTP_NOT_FOUND)
+ return MatchInfoError(HTTPNotFound())
def __iter__(self) -> Iterator[str]:
return iter(self._named_resources) Reverting that seems to fix it.. digging into why its different |
In 3.10 |
That was changed in c11e891 |
Another option is to do a very limited backport of c11e891 |
Co-authored-by: J. Nick Koston <nick@koston.org>
Right, they used to be responses, but now are exceptions. 3.x needs to maintain backwards-compatibility. |
Limited backport POC #7918 (still testing) |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## 3.10 #7917 +/- ##
=======================================
Coverage 97.35% 97.35%
=======================================
Files 108 108
Lines 32459 32542 +83
Branches 3849 3852 +3
=======================================
+ Hits 31600 31682 +82
Misses 655 655
- Partials 204 205 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
This is a backport of PR #7829 as merged into master (2a3eaa1).
What do these changes do?
The time complexity of the UrlDispatcher on a hit averaged
O(n)
The UrlDispatcher now keeps an index of all resources and will attempt to avoid doing a linear search to resolve. On a hit the performance should be nearly
O(url_parts)
on a miss the time complexity will beO(domains) + O(url_parts)
This works for prefixed subapps as well.
sub apps added by
add_domain
(akaMatchedSubAppResource
) will fallback to linear searching as they are not indexable since they support wildcard/regexsAre there changes in behavior for the user?
A fixed/static path will always be preferred over a dynamic path.
Related issue number
fixes #7828
benchmark
before (5002 urls)
before (7 urls)
after (5002 urls)
after (7 urls)
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.