Hi, everyone. I’ve been looking into kotlin wasm a...
# webassembly
l
Hi, everyone. I’ve been looking into kotlin wasm as a way to eventually optimize math performance on JS for some crypto tools I’ve written. https://github.com/eqoty-labs/kryptools Two of the the modules in kryptools are basically pure kotlin with no dependencies. I was wondering would it’s possible at this point to just enable some flags to switch them over to generating wasm for the js target instead of js code?
It would be pretty cool if I could optimize this with wasm to get rid of this terrible cpu usage in js:
s
Hi. We don’t have a Kotlin/Wasm <-> Kotlin/JS interop between modules. One can either compile everything to the same platform or use
external
+
@JsExport
on both sides to glue them manually.
Long
math is indeed currently way faster in Wasm. But Kotlin/JS prerf can probably be improved in the future by using JS BigInt instead of a custom Long class.
b
You can use these examples as a starting point.
l
Thanks for the advice. Is Kotlin/Wasm <-> Kotlin/JS interop between modules a planned feature eventually? Just wondering. Currently can a wasm module depend on another wasm module? @Svyatoslav Kuzmich [JB]
s
Is Kotlin/Wasm <-> Kotlin/JS interop between modules a planned feature eventually?
Not at the moment. Same thing as with other platform combinations. For example, K/JVM cannot just call K/Native without some explicit glue on the boundary.
Currently can a wasm module depend on another wasm module?
Yes. But currently Kotlin/Wasm statically links all source modules into a single Wasm binary.
l
figured out I can generate it with compileDevelopmentExecutableKotlinWasm I couldn’t get it to compile on kotlin 1.7.21 though I got
e: java.lang.IllegalStateException: Internal function 'globalThis' not found
kotlin
1.8.0-Beta
with node
19.0.0
is working though
so now I just need to figure out how to how to call the wasm functions from js
s
Use @JsExport on top level functions and they will appear as properties of default export of .mjs file
Then somehow call the wasm binary from the js code?
You use .mjs wrapper that we generate alongside .wasm file. It’s ES modue
Does this sound feasible?
As long as you use top-level functions, primitive types or
external
types. But
IntArray
have different representation in K/Wasm and K/JS and will have to be copied in a wrapper module.
206 Views