pronoob
pronoob•15mo ago

Is WASM generally faster than using Deno FFI?

...
9 Replies
Mrcool 🇵🇸
I doubt it, you can benchmark though
NeTT
NeTT•15mo ago
FFI should be faster afaik but it depends on whatever you are FFI-ing to
Leokuma
Leokuma•15mo ago
IIRC, Sqlite is a lot faster in FFI than in WASM
Hiro
Hiro•15mo ago
in short FFI will always be faster than WASM because of how it works (being sandboxed and all that)
Kyiro
Kyiro•15mo ago
I kinda but not really benchmarked it once by using rust for image generation wasm was about 2x slower but it's likely caused by the amount of allocating needed it was still decently fast though & wasm_bindgen is more polished than deno_bindgen i couldn't get the latter to work so I had to use raw ffi
pronoob
pronoobOP•15mo ago
What about FFI vs JS for something trivial like adding two numbers? I presume there is an startup overhead for FFI which will make it slower
NDH
NDH•15mo ago
Crossing brain-blood barrier can be costly for small tasks.
lcasdev
lcasdev•15mo ago
Generally WASM is slower than FFI. This does not always matter though. Sometimes you need to use a system API that Deno does not expose bindings for, in which case you must use FFI. However, FFI does not work on Deno Deploy, so WASM may be better suited if you have stronger security restrictions (such as in Deno Deploy).
NeTT
NeTT•15mo ago
yea and there is no difference in performance between native code and JS for such operations FFI will also be slower since it will need to call a function from the lib