]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-115802: Optimize JIT stencils for size (GH-136393)
authorBrandt Bucher <brandtbucher@microsoft.com>
Wed, 9 Jul 2025 19:11:28 +0000 (12:11 -0700)
committerGitHub <noreply@github.com>
Wed, 9 Jul 2025 19:11:28 +0000 (12:11 -0700)
Tools/jit/_targets.py

index ed10329d25d2f961de54053932ae6a85cab4c075..728f48128ce79c7fb8facd91ebb455e500d0f9e5 100644 (file)
@@ -137,7 +137,15 @@ class _Target(typing.Generic[_S, _R]):
             f"-I{CPYTHON / 'Include' / 'internal' / 'mimalloc'}",
             f"-I{CPYTHON / 'Python'}",
             f"-I{CPYTHON / 'Tools' / 'jit'}",
-            "-O3",
+            # -O2 and -O3 include some optimizations that make sense for
+            # standalone functions, but not for snippets of code that are going
+            # to be laid out end-to-end (like ours)... common examples include
+            # passes like tail-duplication, or aligning jump targets with nops.
+            # -Os is equivalent to -O2 with many of these problematic passes
+            # disabled. Based on manual review, for *our* purposes it usually
+            # generates better code than -O2 (and -O2 usually generates better
+            # code than -O3). As a nice benefit, it uses less memory too:
+            "-Os",
             "-S",
             # Shorten full absolute file paths in the generated code (like the
             # __FILE__ macro and assert failure messages) for reproducibility: