From efbb64963df71ea0d54225e7dc2cb95eb44c4557 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sat, 29 Jan 2022 12:37:57 -0800 Subject: [PATCH 1/4] bpo-46576: Disable compiler optimization within test_peg_generator. This speed up test_peg_generator by always disabling compiler optimizations by using -O0 by default when the test is building its own C extensions. A build not using --with-pydebug in order to speed up test execution winds up with this test taking a very long time as it would do repeated compilation of parser C code using the same optimization flags as CPython was built with. This speeds the test up 6-8x on gps-raspbian. --- .../NEWS.d/next/Tests/2022-01-29-12-37-53.bpo-46576.-prRaV.rst | 3 +++ Tools/peg_generator/pegen/build.py | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2022-01-29-12-37-53.bpo-46576.-prRaV.rst diff --git a/Misc/NEWS.d/next/Tests/2022-01-29-12-37-53.bpo-46576.-prRaV.rst b/Misc/NEWS.d/next/Tests/2022-01-29-12-37-53.bpo-46576.-prRaV.rst new file mode 100644 index 00000000000000..737c02943ba1e7 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2022-01-29-12-37-53.bpo-46576.-prRaV.rst @@ -0,0 +1,3 @@ +test_peg_generator now uses -O0 when testing compilation of its own C +extensions to significantly speed up the compilation phase when testing +non-debug builds of CPython. diff --git a/Tools/peg_generator/pegen/build.py b/Tools/peg_generator/pegen/build.py index c69e5c9a5f26a6..1156dc7b48a9e3 100644 --- a/Tools/peg_generator/pegen/build.py +++ b/Tools/peg_generator/pegen/build.py @@ -32,6 +32,7 @@ def compile_c_extension( build_dir: Optional[str] = None, verbose: bool = False, keep_asserts: bool = True, + disable_optimization: bool = True, # Significant test_peg_generator speedup. ) -> str: """Compile the generated source for a parser generator into an extension module. @@ -61,6 +62,8 @@ def compile_c_extension( extra_link_args = get_extra_flags("LDFLAGS", "PY_LDFLAGS_NODIST") if keep_asserts: extra_compile_args.append("-UNDEBUG") + if disable_optimization: + extra_compile_args.append("-O0") extension = [ Extension( extension_name, From 36044f3fa1b419a76b25e856e4fc97874409cff0 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 30 Jan 2022 00:40:22 -0800 Subject: [PATCH 2/4] incorporate #31017's win32 conditional and flags --- Tools/peg_generator/pegen/build.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Tools/peg_generator/pegen/build.py b/Tools/peg_generator/pegen/build.py index 1156dc7b48a9e3..7eac5c4e64b937 100644 --- a/Tools/peg_generator/pegen/build.py +++ b/Tools/peg_generator/pegen/build.py @@ -1,6 +1,7 @@ import itertools import pathlib import shutil +import sys import sysconfig import tempfile import tokenize @@ -63,7 +64,11 @@ def compile_c_extension( if keep_asserts: extra_compile_args.append("-UNDEBUG") if disable_optimization: - extra_compile_args.append("-O0") + if sys.platform == 'win32': + extra_compile_args.append("/Od") + extra_link_args.append("/LTCG:OFF") + else: + extra_compile_args.append("-O0") extension = [ Extension( extension_name, From 42b989cb31b34f274e4dfb0a729378b43632c56a Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 30 Jan 2022 00:41:58 -0800 Subject: [PATCH 3/4] reword news --- .../next/Tests/2022-01-29-12-37-53.bpo-46576.-prRaV.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS.d/next/Tests/2022-01-29-12-37-53.bpo-46576.-prRaV.rst b/Misc/NEWS.d/next/Tests/2022-01-29-12-37-53.bpo-46576.-prRaV.rst index 737c02943ba1e7..be50fc8cbe0a5d 100644 --- a/Misc/NEWS.d/next/Tests/2022-01-29-12-37-53.bpo-46576.-prRaV.rst +++ b/Misc/NEWS.d/next/Tests/2022-01-29-12-37-53.bpo-46576.-prRaV.rst @@ -1,3 +1,3 @@ -test_peg_generator now uses -O0 when testing compilation of its own C -extensions to significantly speed up the compilation phase when testing -non-debug builds of CPython. +test_peg_generator now disables compiler optimization when testing +compilation of its own C extensions to significantly speed up the +testing on non-debug builds of CPython. From c4457db3e0fdd972ec589aa2851c13617f46f6a4 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 30 Jan 2022 22:26:44 -0800 Subject: [PATCH 4/4] Add -fno-lto Co-authored-by: Christian Heimes --- Tools/peg_generator/pegen/build.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tools/peg_generator/pegen/build.py b/Tools/peg_generator/pegen/build.py index 7eac5c4e64b937..78789b94df2e4f 100644 --- a/Tools/peg_generator/pegen/build.py +++ b/Tools/peg_generator/pegen/build.py @@ -69,6 +69,8 @@ def compile_c_extension( extra_link_args.append("/LTCG:OFF") else: extra_compile_args.append("-O0") + if sysconfig.get_config_var("GNULD") == "yes": + extra_link_args.append("-fno-lto") extension = [ Extension( extension_name,