Skip to content

Commit dedd59b

Browse files
authored
Delay loading of link.py. NFC (#20883)
This reduces the overhead of emcc when compiling but not linking. The following result were generated using `multitime -n 5`: ``` Baseline (clang --target=wasm32 -c test/hello_world.c --sysroot=cache/sysroot): Mean Std.Dev. Min Median Max real 0.067 0.002 0.064 0.066 0.070 user 0.036 0.004 0.031 0.037 0.042 sys 0.029 0.005 0.023 0.032 0.034 Before this change (emcc -c test/hello_world.c) Mean Std.Dev. Min Median Max real 0.212 0.004 0.207 0.212 0.218 user 0.159 0.009 0.148 0.155 0.171 sys 0.053 0.009 0.040 0.052 0.064 After this change (emcc -c test/hello_world.c) Mean Std.Dev. Min Median Max real 0.197 0.003 0.192 0.197 0.202 user 0.130 0.009 0.113 0.133 0.136 sys 0.066 0.009 0.057 0.064 0.084 ``` So the overhead of emcc here was reduced from 145ms to 130ms (an 11% reduction).
1 parent c85f1b1 commit dedd59b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

emcc.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
from tools.response_file import substitute_response_files
4545
from tools import config
4646
from tools import cache
47-
from tools import link
4847
from tools.settings import default_setting, user_settings, settings, MEM_SIZE_SETTINGS, COMPILE_TIME_SETTINGS
4948
from tools.utils import read_file, removeprefix
5049

@@ -628,20 +627,24 @@ def run(args):
628627
if state.mode == Mode.POST_LINK_ONLY:
629628
if len(input_files) != 1:
630629
exit_with_error('--post-link requires a single input file')
630+
# Delay import of link.py to avoid processing this file when only compiling
631+
from tools import link
631632
link.run_post_link(input_files[0][1], options, state, newargs)
632633
return 0
633634

634635
## Compile source code to object files
635636
linker_inputs = phase_compile_inputs(options, state, newargs, input_files)
636637

637-
if state.mode != Mode.COMPILE_AND_LINK:
638+
if state.mode == Mode.COMPILE_AND_LINK:
639+
# Delay import of link.py to avoid processing this file when only compiling
640+
from tools import link
641+
return link.run(linker_inputs, options, state, newargs)
642+
else:
638643
logger.debug('stopping after compile phase')
639644
for flag in state.link_flags:
640645
diagnostics.warning('unused-command-line-argument', "argument unused during compilation: '%s'" % flag[1])
641646
return 0
642647

643-
return link.run(linker_inputs, options, state, newargs)
644-
645648

646649
def normalize_boolean_setting(name, value):
647650
# boolean NO_X settings are aliases for X

0 commit comments

Comments
 (0)