Skip to content
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

ConnectionKey hashing and equality has an unexpected impact on performance between master and 3.x #9364

Closed
bdraco opened this issue Oct 1, 2024 · 3 comments · Fixed by #9365

Comments

@bdraco
Copy link
Member

bdraco commented Oct 1, 2024

class ConnectionKey:

We have to hash the ConnectionKey quite a bit.

On 3.x its a attrs with the hash cached
attrs

On master its a dataclass no cache
dataclass

@bdraco
Copy link
Member Author

bdraco commented Oct 1, 2024

Looks like switching it to a NamedTuple will speed it up since the hashing can happen all in native code. Sadly its not cached though

named_tuple

@bdraco
Copy link
Member Author

bdraco commented Oct 1, 2024

Performance regressed in #5284

@bdraco
Copy link
Member Author

bdraco commented Oct 1, 2024

connect with attrs
attrs_connect

connect with namedtuple
namedtuple_connect

bdraco added a commit that referenced this issue Oct 1, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant