-
-
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
Speed up the ConnectionKey #9365
Conversation
A large part of the connection management is constructing, hashing and comparing the connection key For additional details see #9364 To speed this up, ConnectionKey is now a NamedTuple which allows all the __hash__ and __eq__ operations to happen in native code. https://github.com/python/cpython/blob/133e929a791d209b578b4822a7a07f4570b3803b/Objects/tupleobject.c#L319 The construction of the object is a bit faster by calling the yarl URL methods directly
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 #9365 +/- ##
==========================================
+ Coverage 98.07% 98.56% +0.48%
==========================================
Files 105 107 +2
Lines 34908 34976 +68
Branches 4116 4144 +28
==========================================
+ Hits 34237 34473 +236
+ Misses 466 335 -131
+ Partials 205 168 -37
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: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply d684195 on top of patchback/backports/3.11/d684195bb5cb90a85a07b98127a298f3b1ae2ef3/pr-9365 Backporting merged PR #9365 into master
🤖 @patchback |
(cherry picked from commit d684195)
A large part of the connection management is constructing, hashing and comparing the connection key. I noticed this when I was profiling and looking at
py-spy
output to compare which code pathsaiohappyeyeballs
took onmaster
and3.10
For additional details see #9364
To speed this up,
ConnectionKey
is now aNamedTuple
which allows all the__hash__
and__eq__
operations to happen in native code.https://github.com/python/cpython/blob/133e929a791d209b578b4822a7a07f4570b3803b/Objects/tupleobject.c#L319
The construction of the object is a bit faster by calling the
yarl.URL
methods directly.I didn't find any third party code that was altering modifying
connection_key
https://github.com/search?q=req.connection_key&type=code so its likely this change is safe to backport to 3.10 but I was a bit worried about custom proxy Connectors (although that seems unlikely) so I marked it as breaking and only labeled it for 3.11.What do these changes do?
Speed up connections
Are there changes in behavior for the user?
The
ConnectionKey
is now aNamedTuple
Is it a substantial burden for the maintainers to support this?
no
fixes #9364