Is it possible to compile a Kotlin function to Wasm without including the Kotlin stdlib?
Specifically, we have multiple Kotlin/Wasm modules which we’re linking in wasmtime. We are on a limited binary size budget and see there’s about 3kb of duplicated WASM which is unrelated to our function logic in each module.
Ideally we’d be able to load the stdlib once into wasmtime and then link just our additional modules, saving thousands of bytes of space.
Thank you!
j
John Marshall
10/25/2024, 12:10 AM
using an umbrella module so the std is only distributed once for each module would help
Ok, I’ll check that out. But that looks like all the modules would need to be known at compile time?
We’d like to dynamically load these modules into wasmtime at runtime via the Wasmtime c++ integration.
j
John Marshall
10/25/2024, 3:52 AM
yea, it would. alternatively I think you could ship the entire stdlib but then you dont benefit from the tree-shaking reducing it down to just what is required.
👍 1
d
Daniel
10/25/2024, 11:41 AM
That would be ok for us because we’ll have a lot of little libraries, so one large stdlib would be ok. If we wanted to try that approach, do you know how we could compile to WASM without including the stdlib? I wasn’t able to find an existing to compiler option to do so.
Daniel
10/25/2024, 7:53 PM
Actually, looking at my wasm file, I see almost 2.5kb of data related to exception strings and structures. Is there a way to compile to wasm without these exception information?
Daniel
11/05/2024, 1:46 AM
Ok, turns out that in multiplatform 2.0.10-RC they have turned on a more aggressive optimizer and it removes all of the unused wasm which I was seeing in the compiled output. I’m good now.