From a55336e2d08fa4e69d5aeb8679147e5cca0ed31f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 1 Nov 2024 13:37:41 -0500 Subject: [PATCH 1/2] Backport Morsel creation speed up patch from cpython gh-126156 --- ...e-performance-of-creating-Morsel-obj.patch | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 python/3.12/gh-126156-Improve-performance-of-creating-Morsel-obj.patch diff --git a/python/3.12/gh-126156-Improve-performance-of-creating-Morsel-obj.patch b/python/3.12/gh-126156-Improve-performance-of-creating-Morsel-obj.patch new file mode 100644 index 0000000..ecc2af1 --- /dev/null +++ b/python/3.12/gh-126156-Improve-performance-of-creating-Morsel-obj.patch @@ -0,0 +1,39 @@ +From dd3c0fa3fd2795326dae0e0ed63c668f5506cf32 Mon Sep 17 00:00:00 2001 +From: "J. Nick Koston" +Date: Thu, 31 Oct 2024 14:05:40 -0500 +Subject: [PATCH] gh-126156: Improve performance of creating `Morsel` objects + (#126157) + +Replaces the manually constructed loop with a call to `dict.update` +--- + Lib/http/cookies.py | 5 +++-- + .../Library/2024-10-30-00-12-22.gh-issue-126156.BOSqv0.rst | 1 + + 2 files changed, 4 insertions(+), 2 deletions(-) + create mode 100644 Misc/NEWS.d/next/Library/2024-10-30-00-12-22.gh-issue-126156.BOSqv0.rst + +diff --git a/Lib/http/cookies.py b/Lib/http/cookies.py +index 6b9ed24ad8e..d7e8d08b2d9 100644 +--- a/Lib/http/cookies.py ++++ b/Lib/http/cookies.py +@@ -266,6 +266,8 @@ class Morsel(dict): + "samesite" : "SameSite", + } + ++ _reserved_defaults = dict.fromkeys(_reserved, "") ++ + _flags = {'secure', 'httponly'} + + def __init__(self): +@@ -273,8 +275,7 @@ def __init__(self): + self._key = self._value = self._coded_value = None + + # Set default attributes +- for key in self._reserved: +- dict.__setitem__(self, key, "") ++ dict.update(self, self._reserved_defaults) + + @property + def key(self): +-- +2.39.3 (Apple Git-145) + From a06192948f94462368f8e688592165d15829ba14 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 5 Nov 2024 09:44:33 -0600 Subject: [PATCH 2/2] morsel patch for 3.13 --- ...e-performance-of-creating-Morsel-obj.patch | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 python/3.13/gh-126156-Improve-performance-of-creating-Morsel-obj.patch diff --git a/python/3.13/gh-126156-Improve-performance-of-creating-Morsel-obj.patch b/python/3.13/gh-126156-Improve-performance-of-creating-Morsel-obj.patch new file mode 100644 index 0000000..ecc2af1 --- /dev/null +++ b/python/3.13/gh-126156-Improve-performance-of-creating-Morsel-obj.patch @@ -0,0 +1,39 @@ +From dd3c0fa3fd2795326dae0e0ed63c668f5506cf32 Mon Sep 17 00:00:00 2001 +From: "J. Nick Koston" +Date: Thu, 31 Oct 2024 14:05:40 -0500 +Subject: [PATCH] gh-126156: Improve performance of creating `Morsel` objects + (#126157) + +Replaces the manually constructed loop with a call to `dict.update` +--- + Lib/http/cookies.py | 5 +++-- + .../Library/2024-10-30-00-12-22.gh-issue-126156.BOSqv0.rst | 1 + + 2 files changed, 4 insertions(+), 2 deletions(-) + create mode 100644 Misc/NEWS.d/next/Library/2024-10-30-00-12-22.gh-issue-126156.BOSqv0.rst + +diff --git a/Lib/http/cookies.py b/Lib/http/cookies.py +index 6b9ed24ad8e..d7e8d08b2d9 100644 +--- a/Lib/http/cookies.py ++++ b/Lib/http/cookies.py +@@ -266,6 +266,8 @@ class Morsel(dict): + "samesite" : "SameSite", + } + ++ _reserved_defaults = dict.fromkeys(_reserved, "") ++ + _flags = {'secure', 'httponly'} + + def __init__(self): +@@ -273,8 +275,7 @@ def __init__(self): + self._key = self._value = self._coded_value = None + + # Set default attributes +- for key in self._reserved: +- dict.__setitem__(self, key, "") ++ dict.update(self, self._reserved_defaults) + + @property + def key(self): +-- +2.39.3 (Apple Git-145) +