DEV Community

Cover image for Building components in multiple languages - WebAssembly Component Model
Tophe
Tophe

Posted on

Building components in multiple languages - WebAssembly Component Model

The Bytecode Alliance organization maintains a very useful website about The WebAssembly Component Model and each associated languages has also a page on it.

Now that I've explained the purpose of the project and its architecture in the previous section, I will focus on concrete examples of implementing multiple languages in the same project and sharing some tips I had to learn the hard way.

Before choosing a language for compiling to WebAssembly, you should consider the impact it has on the final size of your wasm file - here is a comparaison of the size of the echo plugin in the different languages:

Language Size
C 56K
Rust 72K
Go (with TinyGo) 332K
TypeScript 12M

Looking at the table above, the differences in .wasm file size come from the language and how much runtime support it brings:

  • C and Rust produce very small files (56K and 72K here) because they compile directly to efficient machine-level code without needing to ship a runtime. Rust is slightly larger due to safety checks and standard library overhead, but both remain compact.
  • Go (TinyGo) is larger (332K) because Go normally includes a large runtime. TinyGo reduces this compared to regular Go, but you still pay a higher size cost than C/Rust.
  • TypeScript is much bigger (12M) because it doesn’t compile directly to Wasm. Instead, you’re shipping a whole JavaScript engine runtime inside your .wasm file.

I've already covered creating Rust components, let's now focus on C, Go and TypeScript.

Top comments (0)