emscripten-core / emscripten-core/emscripten

Extremely long link time

Open
#23,034 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Running on version 3.1.60

We have a quite large repository that we build using Emscripten. The link time became quite time-consuming (~2min on Intel i7 12700F), which is unusually long since lld (and its port wasm-ld) should be very fast and typically not the bottleneck in the build process.

We went through the following issue https://github.com/emscripten-core/emscripten/issues/17019 and applied both flags `-sERROR_ON_WASM_CHANGES_AFTER_LINK -sWASM_BIGINT`. We build/link with `-Og`.

This is the `EMPROFILE=2` verbose output for the final link stage:
```
...
profiler:INFO: start block "link"
profiler:INFO: block "link" took 147.589 seconds
profiler:INFO: start block "post link"
profiler:INFO: start block "emscript"
profiler:INFO: start block "get_metadata"
profiler:INFO: block "get_metadata" took 1.040 seconds
profiler:INFO: start block "compile_javascript"
profiler:INFO: block "compile_javascript" took 0.208 seconds
profiler:INFO: block "emscript" took 3.278 seconds
profiler:INFO: start block "binaryen"
profiler:INFO: start block "use_unsigned_pointers_in_js"
profiler:INFO: block "use_unsigned_pointers_in_js" took 0.598 seconds
profiler:INFO: start block "apply_wasm_memory_growth"
profiler:INFO: block "apply_wasm_memory_growth" took 1.007 seconds
profiler:INFO: block "binaryen" took 3.300 seconds
profiler:INFO: start block "final emitting"
profiler:INFO: block "final emitting" took 1.497 seconds
profiler:INFO: block "post link" took 8.077 seconds
profiler:INFO: block "main" took 155.752 seconds
```

These are our build flags:
```
FLAGS = -stdlib=libc++ -pthread -sSHARED_MEMORY=1 -sUSE_PTHREADS=1 LINK_FLAGS = -pthread -sSHARED_MEMORY=1 -sUSE_PTHREADS=1 -sMALLOC=mimalloc "-S --allow-multiple-definition" --closure 1 --closure-args=--jscomp_off=* -sLEGACY_GL_EMULATION -sGL_UNSAFE_OPTS=0 -sGL_FFP_ONLY=1 -WASM=1 --bind -sDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 -sMODULARIZE=1 -sFORCE_FILESYSTEM=1 -sEXPORT_NAME=createModuleFactory -sALLOW_MEMORY_GROWTH=1 -sMALLOC=mimalloc -sINITIAL_MEMORY=1GB -sMAXIMUM_MEMORY=4GB -sPROXY_TO_PTHREAD -sEXIT_RUNTIME=1 -sALLOW_BLOCKING_ON_MAIN_THREAD=1 "-sEXPORTED_RUNTIME_METHODS=['FS','PATH','ERRNO_CODES']" "-sPTHREAD_POOL_SIZE='navigator.hardwareConcurrency*2+1'" -error-limit=0 -sASSERTIONS=1 -sNO_DISABLE_EXCEPTION_CATCHING -gseparate-dwarf -Og --profiling-funcs -sREVERSE_DEPS=all -sWASM_BIGINT -sERROR_ON_WASM_CHANGES_AFTER_LINK
```

Is there anything that you suggest can be done in order to decrease the link time?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.