-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 WebSocketReader #9498
Conversation
Reuses the same idea as aio-libs/yarl#1316 Calling tuple.__new__ is much faster because it avoids the extra runtime lambda https://github.com/python/cpython/blob/d83fcf8371f2f33c7797bc8f5423a8bca8c46e5c/Lib/collections/__init__.py#L441
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 #9498 +/- ##
=======================================
Coverage 98.59% 98.59%
=======================================
Files 105 105
Lines 35093 35097 +4
Branches 4179 4179
=======================================
+ Hits 34600 34604 +4
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.10: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 13dc020 on top of patchback/backports/3.10/13dc0200d855bdfec1d4c4f3e1c9a1c66f88f1eb/pr-9498 Backporting merged PR #9498 into master
🤖 @patchback |
Backport to 3.11: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 13dc020 on top of patchback/backports/3.11/13dc0200d855bdfec1d4c4f3e1c9a1c66f88f1eb/pr-9498 Backporting merged PR #9498 into master
🤖 @patchback |
(cherry picked from commit 13dc020)
(cherry picked from commit 13dc020)
What do these changes do?
Improve performance of WebSocketReader by reducing the overhead to create the
WSMessage
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 messagehttps://github.com/python/cpython/blob/d83fcf8371f2f33c7797bc8f5423a8bca8c46e5c/Lib/collections/__init__.py#L441
I limited the change to the
http_websocket.py
module since this is the only place where they are created at volume. This only works if the object being created is aNamedTuple
so this speed up is only recommended internally and should not be used outside ofaiohttp
since we do not guarantee thatWSMessage
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