Skip to content

Commit 346f75e

Browse files
committed
Speed up running of JS compiler in LLD_REPORT_UNDEFINED mode. NFC
Avoid generating the full JS output, only generate the metadata. This saves about 10% of the cost. See: #16003
1 parent 7c9b97a commit 346f75e

File tree

5 files changed

+36
-28
lines changed

5 files changed

+36
-28
lines changed

emcc.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -508,23 +508,14 @@ def get_all_js_syms():
508508
# TODO(sbc): Find a way to optimize this. Potentially we could add a super-set
509509
# mode of the js compiler that would generate a list of all possible symbols
510510
# that could be checked in.
511-
old_full = settings.INCLUDE_FULL_LIBRARY
512-
try:
513-
# Temporarily define INCLUDE_FULL_LIBRARY since we want a full list
514-
# of all available JS library functions.
515-
settings.INCLUDE_FULL_LIBRARY = True
516-
settings.ONLY_CALC_JS_SYMBOLS = True
517-
emscripten.generate_struct_info()
518-
glue, forwarded_data = emscripten.compile_settings()
519-
forwarded_json = json.loads(forwarded_data)
520-
library_syms = set()
521-
for name in forwarded_json['librarySymbols']:
522-
if shared.is_c_symbol(name):
523-
name = shared.demangle_c_symbol_name(name)
524-
library_syms.add(name)
525-
finally:
526-
settings.ONLY_CALC_JS_SYMBOLS = False
527-
settings.INCLUDE_FULL_LIBRARY = old_full
511+
emscripten.generate_struct_info()
512+
glue, forwarded_data = emscripten.compile_javascript(symbols_only=True)
513+
forwarded_json = json.loads(forwarded_data)
514+
library_syms = set()
515+
for name in forwarded_json:
516+
if shared.is_c_symbol(name):
517+
name = shared.demangle_c_symbol_name(name)
518+
library_syms.add(name)
528519

529520
return library_syms
530521

emscripten.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def apply_static_code_hooks(forwarded_json, code):
179179
return code
180180

181181

182-
def compile_settings():
182+
def compile_javascript(symbols_only=False):
183183
stderr_file = os.environ.get('EMCC_STDERR_FILE')
184184
if stderr_file:
185185
stderr_file = os.path.abspath(stderr_file)
@@ -199,11 +199,18 @@ def compile_settings():
199199
# Call js compiler
200200
env = os.environ.copy()
201201
env['EMCC_BUILD_DIR'] = os.getcwd()
202+
args = [settings_file]
203+
if symbols_only:
204+
args += ['--symbols-only']
202205
out = shared.run_js_tool(path_from_root('src/compiler.js'),
203-
[settings_file], stdout=subprocess.PIPE, stderr=stderr_file,
206+
args, stdout=subprocess.PIPE, stderr=stderr_file,
204207
cwd=path_from_root('src'), env=env, encoding='utf-8')
205-
assert '//FORWARDED_DATA:' in out, 'Did not receive forwarded data in pre output - process failed?'
206-
glue, forwarded_data = out.split('//FORWARDED_DATA:')
208+
if symbols_only:
209+
glue = None
210+
forwarded_data = out
211+
else:
212+
assert '//FORWARDED_DATA:' in out, 'Did not receive forwarded data in pre output - process failed?'
213+
glue, forwarded_data = out.split('//FORWARDED_DATA:')
207214
return glue, forwarded_data
208215

209216

@@ -367,7 +374,7 @@ def emscript(in_wasm, out_wasm, outfile_js, memfile):
367374
if invoke_funcs:
368375
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$getWasmTableEntry']
369376

370-
glue, forwarded_data = compile_settings()
377+
glue, forwarded_data = compile_javascript()
371378
if DEBUG:
372379
logger.debug(' emscript: glue took %s seconds' % (time.time() - t))
373380
t = time.time()

src/compiler.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,18 @@ function load(f) {
4343
// Basic utilities
4444
load('utility.js');
4545

46+
47+
const argv = process.argv.slice(2);
48+
console.error(argv);
49+
const namesOnly = argv.indexOf('--symbols-only');
50+
if (namesOnly != -1) {
51+
argv.splice(namesOnly, 1);
52+
}
53+
54+
global.ONLY_CALC_JS_SYMBOLS = namesOnly != -1;
55+
4656
// Load settings from JSON passed on the command line
47-
const settingsFile = process.argv[2];
57+
const settingsFile = argv[0];
4858
assert(settingsFile);
4959

5060
const settings = JSON.parse(read(settingsFile));

src/jsifier.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,5 +540,10 @@ function ${name}(${args}) {
540540
// Data
541541
functionStubs.forEach(functionStubHandler);
542542

543+
if (ONLY_CALC_JS_SYMBOLS) {
544+
print(JSON.stringify(librarySymbols));
545+
return;
546+
}
547+
543548
finalCombiner();
544549
}

src/settings_internal.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,6 @@ var SEPARATE_DWARF = false;
189189
// New WebAssembly exception handling
190190
var WASM_EXCEPTIONS = false;
191191

192-
// Used internally when running the JS compiler simply to generate list of all
193-
// JS symbols. This is used by LLD_REPORT_UNDEFINED to generate a list of all
194-
// JS library symbols.
195-
var ONLY_CALC_JS_SYMBOLS = false;
196-
197192
// Set to true if the program has a main function. By default this is
198193
// enabled, but if `--no-entry` is passed, or if `_main` is not part of
199194
// EXPORTED_FUNCTIONS then this gets set to 0.

0 commit comments

Comments
 (0)