emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.36k stars 3.25k forks source link

mimalloc adds >60kb into output artifacts #22094

Open jozefchutka opened 2 weeks ago

jozefchutka commented 2 weeks ago

Using em++:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.61 (67fa4c16496b157a7fc3377afd69ee0445e8a6e3)
clang version 19.0.0git (https:/github.com/llvm/llvm-project 7cfffe74eeb68fbb3fb9706ac7071f8caeeb6520)
Target: wasm32-unknown-emscripten
Thread model: posix

Adding -s MALLOC=mimalloc adds additional 52kb into .wasm and 9kb into .js outputs. Is that expected?

Example:

em++ main.cpp -s MALLOC=mimalloc -O3 -o wasm/mfcc.js
# produces: 60kb .wasm + 13kb .js
em++ main.cpp -O3 -o wasm/mfcc.js
# produces: 8kb .wasm  + 4kb .js

Just checking, is that expected? Is the mimalloc so heavy?

kripken commented 2 weeks ago

I believe that is expected, yes. mimalloc is more complex than dlmalloc, and includes additional optimizations, which add a significant amount of code.

It might be worth looking into that in detail to see if we can disable parts of mimalloc that we don't use, I know it has a bunch of flags.

jozefchutka commented 1 week ago

@kripken please let me know if you use this ticket for looking into that in detail to see if we can disable parts of mimalloc else feel free to close it.

kripken commented 1 week ago

Let's leave this open for that purpose, yeah. It is worth looking into, if someone has time.