Skip to content

Commit e8e44e6

Browse files
authored
[mypyc] Use C optimization level 0 for tests by default (#9131)
This speeds up run tests significantly, but it might miss some checks only performed on higher optimization levels. On my Linux desktop, this speeds up `pytest mypyc` from about 18s to about 12s. It should also speed up CI builds, but I haven't measured the impact. Let's try this out. We can always revert this back if this turns out to cause problems. The environment variable MYPYC_OPT_LEVEL can be used to override the optimization level. Example: MYPYC_OPT_LEVEL=3 pytest mypyc Closes mypyc/mypyc#745.
1 parent 19f4fb9 commit e8e44e6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

mypyc/test/test_run.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
5757
setup(name='test_run_output',
5858
ext_modules=mypycify({}, separate={}, skip_cgen_input={!r}, strip_asserts=False,
59-
multi_file={}),
59+
multi_file={}, opt_level='{}'),
6060
)
6161
"""
6262

@@ -240,10 +240,16 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) ->
240240
if incremental_step == 1:
241241
check_serialization_roundtrip(ir)
242242

243+
opt_level = int(os.environ.get('MYPYC_OPT_LEVEL', 0))
244+
243245
setup_file = os.path.abspath(os.path.join(WORKDIR, 'setup.py'))
244246
# We pass the C file information to the build script via setup.py unfortunately
245247
with open(setup_file, 'w', encoding='utf-8') as f:
246-
f.write(setup_format.format(module_paths, separate, cfiles, self.multi_file))
248+
f.write(setup_format.format(module_paths,
249+
separate,
250+
cfiles,
251+
self.multi_file,
252+
opt_level))
247253

248254
if not run_setup(setup_file, ['build_ext', '--inplace']):
249255
if testcase.config.getoption('--mypyc-showc'):

0 commit comments

Comments
 (0)