Skip to content

Commit f5ebec4

Browse files
authored
[3.10] bpo-46576: bpo-46524: Disable compiler optimization within test_peg_generator. (GH-31015) (GH-31089)
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]>
1 parent 2ddc278 commit f5ebec4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
Lines changed: 3 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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
@@ -62,6 +64,14 @@ def compile_c_extension(
6264
extra_link_args = get_extra_flags("LDFLAGS", "PY_LDFLAGS_NODIST")
6365
if keep_asserts:
6466
extra_compile_args.append("-UNDEBUG")
67+
if disable_optimization:
68+
if sys.platform == 'win32':
69+
extra_compile_args.append("/Od")
70+
extra_link_args.append("/LTCG:OFF")
71+
else:
72+
extra_compile_args.append("-O0")
73+
if sysconfig.get_config_var("GNULD") == "yes":
74+
extra_link_args.append("-fno-lto")
6575
extension = [
6676
Extension(
6777
extension_name,

0 commit comments

Comments
 (0)