sdeleuze
08/14/2022, 12:19 PM1.7.20-Beta
, I try to use Binaryen to optimize the generated Wasm but it fails:
wasm-opt build/compileSync/main/productionExecutable/kotlin/add-wasm.wasm -o build/compileSync/main/productionExecutable/kotlin/add-wasm-opt.wasm --enable-nontrapping-float-to-int --enable-typed-function-references --enable-gc --enable-reference-types --enable-exception-handling -O3 --inline-functions-with-loops --traps-never-happen --fast-math
[parse exception: Recursion groups not allowed with equirecursive typing (at 0:15)]
Fatal: error parsing wasm
Could you please share what version/parameters I should use?
The related sample is available on https://github.com/sdeleuze/wasm-footprint/tree/main/kotlin.fun main() {
add(2, 3)
}
fun add(a: Int, b: Int) = a + b
And in the generated 1.1M wasm most of the footprint is taken by collection and exception infra:
❯ grep $kotlin.collections build/compileSync/main/productionExecutable/kotlin/add-wasm.wat | wc -l
774
❯ grep Exception build/compileSync/main/productionExecutable/kotlin/add-wasm.wat | wc -l
346
Is it due to the fact I am not using wasm-opt
?Svyatoslav Kuzmich [JB]
08/17/2022, 2:13 PM--hybrid
is whats causing the error.sdeleuze
08/18/2022, 5:43 PM--hybrid
that works as expected:
exa -l build/compileSync/main/productionExecutable/kotlin/
.rw-r--r-- 15k seb 18 Aug 19:41 add-wasm-opt.wasm
.rw-r--r-- 4.5k seb 14 Aug 13:58 add-wasm.mjs
.rw-r--r-- 156k seb 14 Aug 13:58 add-wasm.wasm
.rw-r--r-- 1.1M seb 14 Aug 13:58 add-wasm.wat
After optimization the generated Wasm file is 10x smaller.wasm-opt
is able to optimize the size that much? Is it doing a second pass of code removal of unreachable code paths after Kotlin/Wasm?