From 7daa20ff26002eb832636be049c8e3dbcde98a8e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 3 Oct 2024 11:11:21 -0500 Subject: [PATCH 1/6] Add __slots__ to timer helpers We use __slots__ almost everywhere else in the codebase, however __slots__ was missing for these helpers related issue #4618 --- aiohttp/helpers.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/aiohttp/helpers.py b/aiohttp/helpers.py index 8474bb735c9..ec67abf5ebf 100644 --- a/aiohttp/helpers.py +++ b/aiohttp/helpers.py @@ -596,6 +596,8 @@ def calculate_timeout_when( class TimeoutHandle: """Timeout handle""" + __slots__ = ("_timeout", "_loop", "_ceil_threshold", "_callbacks") + def __init__( self, loop: asyncio.AbstractEventLoop, @@ -644,11 +646,17 @@ def __call__(self) -> None: class BaseTimerContext(ContextManager["BaseTimerContext"]): + + __slots__ = () + def assert_timeout(self) -> None: """Raise TimeoutError if timeout has been exceeded.""" class TimerNoop(BaseTimerContext): + + __slots__ = () + def __enter__(self) -> BaseTimerContext: return self @@ -664,6 +672,8 @@ def __exit__( class TimerContext(BaseTimerContext): """Low resolution timeout context manager""" + __slots__ = ("_loop", "_tasks", "_cancelled", "_cancelling") + def __init__(self, loop: asyncio.AbstractEventLoop) -> None: self._loop = loop self._tasks: List[asyncio.Task[Any]] = [] From 48386d8779f18bc79083d12448ed1e1d50290d41 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 3 Oct 2024 11:28:29 -0500 Subject: [PATCH 2/6] fix --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index c4f6587a753..74a8d7d7e4e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,3 +82,8 @@ skip = "pp*" [tool.codespell] skip = '.git,*.pdf,*.svg,Makefile,CONTRIBUTORS.txt,venvs,_build' ignore-words-list = 'te,assertIn' + +[tool.slotscheck] +# Remove require-superclass = false once https://github.com/python/cpython/pull/106771 +# is available in all supported cpython versions +require-superclass = false From bed9b91d6396b8b7dd507419075a4f3ad06ae754 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 3 Oct 2024 12:50:17 -0500 Subject: [PATCH 3/6] changelog --- CHANGES/9406.misc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/9406.misc.rst diff --git a/CHANGES/9406.misc.rst b/CHANGES/9406.misc.rst new file mode 100644 index 00000000000..0a0f7e78677 --- /dev/null +++ b/CHANGES/9406.misc.rst @@ -0,0 +1 @@ +Reduced memory required for timer objects created during the client request lifecycle -- by :user:`bdraco`. From 1de6d9914d89b717f1cafd9dd5658caf51fe0f3c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 3 Oct 2024 12:54:01 -0500 Subject: [PATCH 4/6] limit exclude --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 74a8d7d7e4e..96903940a05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,6 +84,6 @@ skip = '.git,*.pdf,*.svg,Makefile,CONTRIBUTORS.txt,venvs,_build' ignore-words-list = 'te,assertIn' [tool.slotscheck] -# Remove require-superclass = false once https://github.com/python/cpython/pull/106771 +# Remove aiohttp.helkpers once https://github.com/python/cpython/pull/106771 # is available in all supported cpython versions -require-superclass = false +exclude-modules = "(^aiohttp\\.helpers)" From 6b504a58f4342c667779883c08ea7e787ffa2abb Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 3 Oct 2024 12:54:31 -0500 Subject: [PATCH 5/6] Update pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 96903940a05..a499d972f39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,6 +84,6 @@ skip = '.git,*.pdf,*.svg,Makefile,CONTRIBUTORS.txt,venvs,_build' ignore-words-list = 'te,assertIn' [tool.slotscheck] -# Remove aiohttp.helkpers once https://github.com/python/cpython/pull/106771 +# Remove aiohttp.helpers once https://github.com/python/cpython/pull/106771 # is available in all supported cpython versions exclude-modules = "(^aiohttp\\.helpers)" From 986129bc0146756123ecce853a84a4c32e62529e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 3 Oct 2024 15:53:53 -0500 Subject: [PATCH 6/6] Update pyproject.toml Co-authored-by: Sam Bull --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a499d972f39..8b83775c740 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,6 +84,6 @@ skip = '.git,*.pdf,*.svg,Makefile,CONTRIBUTORS.txt,venvs,_build' ignore-words-list = 'te,assertIn' [tool.slotscheck] -# Remove aiohttp.helpers once https://github.com/python/cpython/pull/106771 +# TODO(3.13): Remove aiohttp.helpers once https://github.com/python/cpython/pull/106771 # is available in all supported cpython versions exclude-modules = "(^aiohttp\\.helpers)"