r/webdev • u/zionsati • 4h ago
Showoff Saturday Showoff Saturday: C# is now smaller than Rust in Wasm - 13.5 KB Brotli
I've been building NetWasm, an independent C# compiler and runtime for WebAssembly.
The latest release produced a result I honestly didn't expect when I started this project:
NetWasm 0.8.0 + precise GC
- 47,798 bytes raw
- 13,501 bytes Brotli-11
Rust 1.95.0, size-oriented
- 53,635 bytes raw
- 16,963 bytes Brotli-11
Same print-42 workload, both WASI Preview 2 components, out of the box dev experience.
So C# is 10.9% smaller raw and 20.4% smaller compressed in this comparison - while carrying a precise garbage collector.
I'm not claiming arbitrary C# programs are smaller than arbitrary Rust programs. This is the classic tiny console-output footprint test: deliberately little application code so you can see how much runtime/toolchain baggage you're carrying.
The reason I care about this for web development is that download size matters.
I've always wanted C# in the browser without accepting a giant runtime as the entry fee.
Since I last talked about NetWasm, it can now do quite a bit more than tiny benchmarks:
- C# Web Workers, with each worker getting its own Wasm instance, heap and event loop
- Compile complete multi-file C# projects entirely in the browser
- Statically link native Wasm
.alibraries throughLibraryImport - Native-to-managed callbacks
- C# 15
- Expression trees through a bounded interpreter, without general reflection
- HTTP/JSON/XML/Regex and a growing set of
Microsoft.Extensions.*libraries - Multiple GC/allocation strategies depending on whether you care more about size or throughput
There's also a NetWasm port of RegexStorm - regexstorm.netwasm.com - that runs entirely client-side in the browser - no backend doing the regex work.
The bigger idea behind NetWasm is pretty simple:
C# shouldn't inherently mean shipping megabytes of runtime.
For browser UI workloads in particular, I want a model where you only ship the runtime machinery your application actually uses.
The Rust comparison is fun, but that's the part I'm really interested in: how small can a genuinely useful managed-language platform become when Wasm is treated as the primary target rather than something a desktop runtime also happens to support?
Would be especially interested in thoughts from people building larger Wasm/browser applications - the project is early so this is your chance to help shape the direction.



