I'm not 100% sure, because my app is growing quick...
# webassembly
r
I'm not 100% sure, because my app is growing quickly, but I think binaryen optimization in Kotlin 2.0.20 takes much more time than before. Anyone has similar observations?
1
b
Gradle build scan before and after could be helpful.
Also you can check the time with other binaryen version, like:
Copy code
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenRootExtension>().apply { 
    version = "117" 
}
@Ilya Goncharov [JB] jfyi
@Robert Jaros do you use production build or apply binaryen to dev builds?
r
Production
b
Do you use it often? If so, why?
(I’m just trying to understand your workflow and how much the problem affects you)
r
I'm not using it often. I'm testing from time to time. I was just surprised how long does it take. At first I was sure something was broken and I've killed the process. After a few tries I've just let it finish the work. It currently takes about 4 minutes for my application.
It processes 12MB wasm file into 3,6MB file.
b
Could you please provide numbers (build scans might be better) with both 117 and current (118) binaryen?
r
binaryen 117 is a bit faster - 3m47s vs 4m13s, but I don't think this is so much different. I think it must be my application - perhaps it is just quite big now ;>
b
ok, thanks for checking
a
it was working fine on 1.9.24 , after upgrade to 2.0.20 it works on my local (mac m1) but on the CI it hangs long time (30 min) then throw this error
Copy code
> Task :webApp:compileProductionExecutableKotlinWasmJsOptimize FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':webApp:compileProductionExecutableKotlinWasmJsOptimize'.
> Process 'command 'root-project/.gradle/binaryen/binaryen-version_118/bin/wasm-opt'' finished with non-zero exit value 139
i'll try to downgrade to 117
b
@Ahmed na Looks like a bug (SIGSEGV) in binaryen
a
After trying couple of solutions found in the threads , this is what worked for me
Copy code
// root gradle.properties
kotlin.daemon.jvmargs=-Xmx6g -Xms3g
Copy code
// project/build.gradle.kts

rootProject.the<org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenRootExtension>().apply {
    version = "117"
}

tasks.withType<org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenExec> {
    binaryenArgs = mutableListOf(
        // Required flags:
        "--enable-gc",
        "--enable-reference-types",
        "--enable-exception-handling",
        "--enable-bulk-memory",
        "--enable-nontrapping-float-to-int",

        // Optional flags (can be removed):
        "--inline-functions-with-loops",
        "--traps-never-happen",
        "--fast-math",
//        "-O3", <--- comment this
//        "-O3", <--- comment this
        "--gufa",
//        "-O3", <--- comment this
//        "-O3", <--- comment this
        "-Oz",
    )
}
then run
Copy code
export BINARYEN_PASS_DEBUG=1
./gradlew :webApp:wasmJsBrowserDistribution --no-configuration-cache