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

DNM: Add a Cython implementation for ConnectionKey with hash caching #10072

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions aiohttp/_client_reqrep.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cdef class ConnectionKey:

cdef readonly str host
cdef readonly object port
cdef readonly bint is_ssl
cdef readonly object ssl
cdef readonly object proxy
cdef readonly object proxy_auth
cdef readonly object proxy_headers_hash
cdef readonly Py_hash_t _hash

def __init__(self, host, port, is_ssl, ssl, proxy, proxy_auth, proxy_headers_hash):
self.host = host
self.port = port
self.is_ssl = is_ssl
self.ssl = ssl
self.proxy = proxy
self.proxy_auth = proxy_auth
self.proxy_headers_hash = proxy_headers_hash
self._hash = hash((host, port, is_ssl, ssl, proxy, proxy_auth, proxy_headers_hash))

def __hash__(self):
return self._hash

def __eq__(self, other: ConnectionKey):
if not isinstance(other, ConnectionKey):
return NotImplemented
return (
self.host == other.host and
self.port == other.port and
self.is_ssl == other.is_ssl and
self.ssl == other.ssl and
self.proxy == other.proxy and
self.proxy_auth == other.proxy_auth and
self.proxy_headers_hash == other.proxy_headers_hash
)
14 changes: 14 additions & 0 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from .hdrs import CONTENT_TYPE
from .helpers import (
_SENTINEL,
NO_EXTENSIONS,
BaseTimerContext,
BasicAuth,
HeadersMixin,
Expand Down Expand Up @@ -1239,3 +1240,16 @@ async def __aexit__(
# if state is broken
self.release()
await self.wait_for_close()


RawResponseMessagePy = ConnectionKey
bdraco marked this conversation as resolved.
Show resolved Hide resolved

try:
if not NO_EXTENSIONS:
from ._client_repreq import ( # type: ignore[import-not-found,no-redef]
ConnectionKey,
)

ConnectionKeyC = ConnectionKey
except ImportError: # pragma: no cover
pass
Loading