bytecodealliance / bytecodealliance/StarlingMonkey
Running `meta-dce` build step
- Dominant language
- C
- Stars
- 288
- Forks
- 57
- PR merge metrics
- No merged PRs in 30d
Description
I was recently looking into ways to reduce the size of the StarlingMonkey image, which currently sits at around 11MB. One of the interesting tools that we could perhaps use is [wasm-metadce](https://github.com/WebAssembly/binaryen/wiki/Pruning-unneeded-code-in-wasm-files-with-wasm-metadce).
tl;dr: `wasm-metadce` takes a JSON file that describes the module tree and performs dead code elimination on the entire graph of both the wasm and the outside code. For example, I would imagine something like this for StarlingMonkey:
```json
[
{
"name": "outside",
"reaches": [
"wasi-cli",
"wasi-http",
"wizer-resume",
"cabi-realloc",
"export-memory"
],
"root": true
},
{
"name": "wasi-cli",
"export": "wasi:cli/run@0.2.3#run"
},
{
"name": "wasi-http",
"export": "wasi:http/incoming-handler@0.2.3#handle"
},
{
"name": "wizer-resume",
"export": "wizer.resume"
},
{
"name": "cabi-realloc",
"export": "cabi_realloc"
},
{
"name": "export-memory",
"export": "memory"
}
]
```
In fact I tried to integrate this tool to our build system and this is what it was able to DCE:
```
unused: func$JS::Realm::resetRandomNumberGenerator\28\29
unused: func$__env_rm_add
unused: func$__wasilibc_deinitialize_environ
unused: func$__wizer_initialize\28\29
unused: func$_initialize
unused: func$api::Engine::finish_pre_initialization\28\29
unused: func$clearenv
unused: func$js::ResetMathRandomSeed\28JSContext*\29
unused: func$std::__2::basic_istream>&\20std::__2::getline\5babi:v160000\5d\2c\20std::__2::allocator>\28std::__2::basic_istream>&\2c\20std::__2::basic_string\2c\20std::__2::allocator>&\29
unused: func$std::__2::basic_istream>&\20std::__2::getline\5babi:v160000\5d\2c\20std::__2::allocator>\28std::__2::basic_istream>&\2c\20std::__2::basic_string\2c\20std::__2::allocator>&\2c\20char\29
unused: func$std::__2::basic_istream>::sentry::operator\20bool\5babi:v160000\5d\28\29\20const
unused: func$std::__2::basic_istream>::sentry::sentry\28std::__2::basic_istream>&\2c\20bool\29
unused: func$std::__2::char_traits::eq\28char\2c\20char\29
unused: func$std::__2::istreambuf_iterator>::istreambuf_iterator\5babi:v160000\5d\28\29
unused: func$std::__2::istreambuf_iterator>::istreambuf_iterator\5babi:v160000\5d\28std::__2::basic_istream>&\29
unused: func$wizen\28\29
```
It looks like it only removed the dependencies related to `wizer` initialization. I guess my question is: are there anything specific that might be preventing `wasm-metadce` from identifying additional dead code and make the dependency analysis overly conservative?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.