Skip to content

Commit e825860

Browse files
[3.9] [3.10] bpo-46576: bpo-46524: Disable compiler optimization within test_peg_generator. (GH-31015) (GH-31089) (GH-31093)
Disable compiler optimization within test_peg_generator. This speed up test_peg_generator by always disabling compiler optimizations by using -O0 or equivalent 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. Also incorporate's GH-31017's win32 conditional and flags. Co-authored-by: Kumar Aditya kumaraditya303. (cherry picked from commit 164a017) Co-authored-by: Gregory P. Smith <[email protected]> (cherry picked from commit f5ebec4) Co-authored-by: Gregory P. Smith <[email protected]> Automerge-Triggered-By: GH:gpshead
1 parent fafd2da commit e825860

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test_peg_generator now disables compiler optimization when testing
2+
compilation of its own C extensions to significantly speed up the
3+
testing on non-debug builds of CPython.

Tools/peg_generator/pegen/build.py

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pathlib
22
import shutil
33
import tokenize
4+
import sys
45
import sysconfig
56
import tempfile
67
import itertools
@@ -33,6 +34,7 @@ def compile_c_extension(
3334
build_dir: Optional[str] = None,
3435
verbose: bool = False,
3536
keep_asserts: bool = True,
37+
disable_optimization: bool = True, # Significant test_peg_generator speedup.
3638
) -> str:
3739
"""Compile the generated source for a parser generator into an extension module.
3840
@@ -59,6 +61,14 @@ def compile_c_extension(
5961
extra_link_args = get_extra_flags("LDFLAGS", "PY_LDFLAGS_NODIST")
6062
if keep_asserts:
6163
extra_compile_args.append("-UNDEBUG")
64+
if disable_optimization:
65+
if sys.platform == 'win32':
66+
extra_compile_args.append("/Od")
67+
extra_link_args.append("/LTCG:OFF")
68+
else:
69+
extra_compile_args.append("-O0")
70+
if sysconfig.get_config_var("GNULD") == "yes":
71+
extra_link_args.append("-fno-lto")
6272
extension = [
6373
Extension(
6474
extension_name,

0 commit comments

Comments
 (0)