I’ve known for a while now that Typst supports WebAssembly plugins, but I haven’t seen a package that utilises it (at least not consciously).
So I wanted to ask: What are some uses for WebAssembly in Typst? What packages are using WebAssembly for what functionality? Why is it preferrable to regular Typst code?
You need to keep the limitation in mind that plugins can only communicate (to and back) via bytes/strings. They cannot create content, apply set rules or accept a function as parameter.
Where they shine is heavy computations with (usually but not always) relatively simple input and output. A good example would be mathematical computations. You can encode a float into bytes, send it to a plugin, let it perform a complex computation and send the result back.
I have just one package that uses plugins: Komet. It falls right into this category.
Other good applications are packages that generate QR codes (input: link, output: bit matrix) or transform or generate images. Plugins are also good if you want to do something that needs a library written in C or Rust for a complex task and which does not exist as a Typst package.
Usually the plugin output needs to be postprocessed with Typst code.
A major downside for plugins is the immense overhead in implementation. Also the data transfer to and from the plugin can be costly. For small data amounts and little computations it is just not worth it. That being said you should measure whether performance is really bad with pure Typst code and whether it improves with a plugin.
Keep in mind that binary plugin sizes can easily blow up while Typst code is small in size. This xan matter for package downloads when the plugin size is in the megabytes.