From c85f1e47c98fe14c937d4cc33dd357cbf3504657 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 17 Sep 2024 22:01:02 +0200 Subject: [PATCH 1/3] Speed up starting compression Enumerating a enum and accessing all the .value is not performant. Switching to a dict is significantly faster --- aiohttp/web_response.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/aiohttp/web_response.py b/aiohttp/web_response.py index f1c25ba4e87..4f2f5d2f8d3 100644 --- a/aiohttp/web_response.py +++ b/aiohttp/web_response.py @@ -65,6 +65,8 @@ class ContentCoding(enum.Enum): identity = "identity" +CONTENT_CODINGS = {coding.value: coding for coding in ContentCoding} + ############################################################ # HTTP Response classes ############################################################ @@ -341,8 +343,8 @@ async def _start_compression(self, request: "BaseRequest") -> None: # Encoding comparisons should be case-insensitive # https://www.rfc-editor.org/rfc/rfc9110#section-8.4.1 accept_encoding = request.headers.get(hdrs.ACCEPT_ENCODING, "").lower() - for coding in ContentCoding: - if coding.value in accept_encoding: + for value, coding in CONTENT_CODINGS.items(): + if value in accept_encoding: await self._do_start_compression(coding) return From 46c29db5c63cf93580ca169c2c81efd2d339e33e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 18 Sep 2024 07:19:19 +0200 Subject: [PATCH 2/3] changelog --- CHANGES/9169.misc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/9169.misc.rst diff --git a/CHANGES/9169.misc.rst b/CHANGES/9169.misc.rst new file mode 100644 index 00000000000..3300ffd2431 --- /dev/null +++ b/CHANGES/9169.misc.rst @@ -0,0 +1 @@ +Improved performance of starting compression for web requests -- by :user:`bdraco`. From 03afd40908be254c7c22cf5b2e7e8b929da25b3e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 18 Sep 2024 16:40:20 +0200 Subject: [PATCH 3/3] symlink --- CHANGES/9169.misc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 120000 CHANGES/9169.misc.rst diff --git a/CHANGES/9169.misc.rst b/CHANGES/9169.misc.rst deleted file mode 100644 index 3300ffd2431..00000000000 --- a/CHANGES/9169.misc.rst +++ /dev/null @@ -1 +0,0 @@ -Improved performance of starting compression for web requests -- by :user:`bdraco`. diff --git a/CHANGES/9169.misc.rst b/CHANGES/9169.misc.rst new file mode 120000 index 00000000000..d6a2f2aaaab --- /dev/null +++ b/CHANGES/9169.misc.rst @@ -0,0 +1 @@ +9174.misc.rst \ No newline at end of file