-
-
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
Improve performance of creating the ConnectionKey #9499
Conversation
Reuses the same idea as aio-libs/yarl#1316 and aio-libs/yarl#1322 Calling `tuple.__new__` is much faster because it avoids the extra runtime lambda having to be run and arguments unpacked for every message https://github.com/python/cpython/blob/d83fcf8371f2f33c7797bc8f5423a8bca8c46e5c/Lib/collections/__init__.py#L441 This only works if the object being created is a `NamedTuple` so this speed up is only recommended internally and should not be used outside of `aiohttp` since we do not guarantee that ConnectionKey will remain a `NamedTuple` in the future.
Can only backport to 3.11 since |
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## master #9499 +/- ##
=======================================
Coverage 98.59% 98.59%
=======================================
Files 105 105
Lines 35093 35093
Branches 4179 4179
=======================================
Hits 34600 34600
Misses 329 329
Partials 164 164
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Backport to 3.11: 💚 backport PR created✅ Backport PR branch: Backported as #9500 🤖 @patchback |
(cherry picked from commit b45a7da)
…e ConnectionKey (#9500) Co-authored-by: J. Nick Koston <nick@koston.org>
What do these changes do?
Improve performance of the client by reducing the overhead to create the
ConnectionKey
objects.Reuses the same idea as aio-libs/yarl#1316 and aio-libs/yarl#1322
Calling
tuple.__new__
is much faster because it avoids the extra runtime lambda having to be run and arguments unpacked for every message https://github.com/python/cpython/blob/d83fcf8371f2f33c7797bc8f5423a8bca8c46e5c/Lib/collections/__init__.py#L441This only works if the object being created is a
NamedTuple
so this speed up is only recommended internally and should not be used outside ofaiohttp
since we do not guarantee that ConnectionKey will remain aNamedTuple
in the future.Are there changes in behavior for the user?
no
Is it a substantial burden for the maintainers to support this?
no