emscripten-core / emscripten-core/emscripten
Large link time regression compared to fastcomp
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
After updating our compiler from 1.38.11 to 2.0.19, we are seeing a very large regression in `wasm-ld` link times in a large project, with link times taking up to 15 minutes(!), or about twice as slow as fastcomp.
Taking a look at this regression in Visual Studio 2019 performance profiler, there are two functions that consume ~65.4% of the total link time, `llvm::Function::hasAddressTaken` and `hasChangeableCC`:

Looking inside these two functions, they both have a hotspot in the same location: an inlined call to a seemingly `dynamic_cast<>`/`reinterpret_cast<>` like `isa()` check:


To reproduce this issue, throw me a mail or a message at Discord, the test case is unfortunately a bit larger than what can be directly attached here. Unzip the files to Emscripten root directory, and then run
```
C:\emsdk\emscripten\main>embuilder build MINIMAL
C:\emsdk\emscripten\main>wasm-ld -o 1.wasm 1.a 2.a 3.a 4.a 5.a 6.a 7.a 8.a 9.a 10.a 11.a 12.a 13.a 14.a 15.a 16.a 17.a 18.a 19.a 20.a 21.a 22.a 23.a 24.a 25.a 26.a 27.a 28.a 29.a 30.a 31.a 32.a 33.a 34.a 35.a 36.a 37.a 38.a 39.a 40.a 41.a 42.a 43.a 44.a 45.a 46.a 47.a 48.a 49.a 50.a 51.a 52.a 53.a 54.a 55.a 56.a 57.a 58.a 59.a 60.a 61.a 62.a 63.a -Lcache/sysroot/lib/wasm32-emscripten cache/sysroot/lib/wasm32-emscripten/libgl-webgl2-full_es3.a cache/sysroot/lib/wasm32-emscripten/libal.a cache/sysroot/lib/wasm32-emscripten/libhtml5.a cache/sysroot/lib/wasm32-emscripten/libc.a cache/sysroot/lib/wasm32-emscripten/libcompiler_rt.a cache/sysroot/lib/wasm32-emscripten/libc++.a cache/sysroot/lib/wasm32-emscripten/libc++abi.a cache/sysroot/lib/wasm32-emscripten/libdlmalloc.a cache/sysroot/lib/wasm32-emscripten/libc_rt_wasm.a cache/sysroot/lib/wasm32-emscripten/libsockets.a -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined --export main --export emscripten_stack_get_end --export emscripten_stack_get_free --export emscripten_stack_init --export __cxa_demangle --export stackSave --export stackRestore --export stackAlloc --export __wasm_call_ctors --export fflush --export __errno_location --export malloc --export free --export __cxa_is_pointer_type --export __cxa_can_catch --export setThrew --export ntohs --export strlen --export htonl --export htons --export memset --export _get_tzname --export _get_daylight --export _get_timezone --export memalign --export emscripten_main_thread_process_queued_calls --export emscripten_webgl_make_context_current --export emscripten_webgl_get_current_context --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-table -z stack-size=5242880 --initial-memory=33554432 --no-entry --max-memory=2147483648 --global-base=1024
```
Contributor guide
Assessment
This issue has not been assessed yet.