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

[PR #8681/30a3d0ef backport][3.10] Improve performance of starting request handlers with Python 3.12+ #8725

Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions CHANGES/8681.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Improved performance of starting request handlers with Python 3.12+ -- by :user:`bdraco`.

This change is a followup to :issue:`8661` to make the same optimization for Python 3.12+ where the request is connected.
10 changes: 8 additions & 2 deletions aiohttp/web_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,16 @@ def connection_made(self, transport: asyncio.BaseTransport) -> None:
if self._tcp_keepalive:
tcp_keepalive(real_transport)

self._task_handler = self._loop.create_task(self.start())
assert self._manager is not None
self._manager.connection_made(self, real_transport)

loop = self._loop
if sys.version_info >= (3, 12):
task = asyncio.Task(self.start(), loop=loop, eager_start=True)
else:
task = loop.create_task(self.start())
self._task_handler = task

def connection_lost(self, exc: Optional[BaseException]) -> None:
if self._manager is None:
return
Expand Down Expand Up @@ -494,7 +500,7 @@ async def start(self) -> None:
keep_alive(True) specified.
"""
loop = self._loop
handler = self._task_handler
handler = asyncio.current_task(loop)
assert handler is not None
manager = self._manager
assert manager is not None
Expand Down
Loading