From 7fb3f2295534a3cc0ce45779fc8f070e506e554d Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Thu, 20 Jan 2022 10:07:16 +0530 Subject: [PATCH 1/3] deepfreeze use preallocated small ints --- Tools/scripts/deepfreeze.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py index 002d680e10c2f6..8f5c454cbea552 100644 --- a/Tools/scripts/deepfreeze.py +++ b/Tools/scripts/deepfreeze.py @@ -113,6 +113,7 @@ def __init__(self, file: TextIO): self.write('#include "Python.h"') self.write('#include "internal/pycore_gc.h"') self.write('#include "internal/pycore_code.h"') + self.write('#include "internal/pycore_long.h"') self.write("") @contextlib.contextmanager @@ -313,6 +314,8 @@ def _generate_int_for_bits(self, name: str, i: int, digit: int) -> None: self.write(f".ob_digit = {{ {ds} }},") def generate_int(self, name: str, i: int) -> str: + if -5 <= i <= 256: + return f"(PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS + {i}]" if abs(i) < 2**15: self._generate_int_for_bits(name, i, 2**15) else: From 462b8990b39905c1b2ca7eaef5241880624bb6dc Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 20 Jan 2022 05:27:09 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Misc/NEWS.d/next/Build/2022-01-20-05-27-07.bpo-46443.udCVII.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Build/2022-01-20-05-27-07.bpo-46443.udCVII.rst diff --git a/Misc/NEWS.d/next/Build/2022-01-20-05-27-07.bpo-46443.udCVII.rst b/Misc/NEWS.d/next/Build/2022-01-20-05-27-07.bpo-46443.udCVII.rst new file mode 100644 index 00000000000000..8e3fa197be9da4 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2022-01-20-05-27-07.bpo-46443.udCVII.rst @@ -0,0 +1 @@ +Deepfreeze now uses cached small integers as it saves some space for common small integers. \ No newline at end of file From 1dfecc0c17fa967c51f499a89f4fcbbd4c91b033 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Thu, 20 Jan 2022 11:13:15 +0530 Subject: [PATCH 3/3] use cached empty bytes object --- Tools/scripts/deepfreeze.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py index 8f5c454cbea552..49638b8400285c 100644 --- a/Tools/scripts/deepfreeze.py +++ b/Tools/scripts/deepfreeze.py @@ -149,6 +149,8 @@ def field(self, obj: object, name: str) -> None: self.write(f".{name} = {getattr(obj, name)},") def generate_bytes(self, name: str, b: bytes) -> str: + if b == b"": + return "(PyObject *)&_Py_SINGLETON(bytes_empty)" self.write("static") with self.indent(): with self.block("struct"):