BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News .NET WebAssembly Support an Ongoing Experiment

.NET WebAssembly Support an Ongoing Experiment

This item in japanese

Bookmarks

WebAssembly now ships on by default in the four major browsers and the .NET community continues to push forward to provide .NET developers the ability to compile their to WebAssembly and run it in the browser.

WebAssembly is the binary web format aimed at running apps with near-native performance using languages that aren't JavaScript. Currently, C, C++, and Rust can compile to the wasm format via LLVM-based toolchain. These languages compile to native code and can be sent down the wire without any additional code. Of course, .NET normally requires a platform runtime to execute code, so using it in the browser is theoretically possible, but requires some extra work to make it work efficiently

One of the most exciting possibilities is a project by Steve Sanderson called Blazor. It's still an ongoing experiment and something production-worthy is still very far off. Blazor runs interpreted .NET code on top of a Mono runtime that is compiled to wasm. Currently, this results in a larger than desired payload for a "Hello World" app, says Sanderson:

Since moving to the Mono runtime, new Blazor applications have temporarily become huge (~4MB). This is because Mono on WASM doesn't yet have any IL stripping or minification, and bundles a large runtime that includes many desktop-related features that are irrelevant on the web. I expect that a web-optimised production application would be a fraction of this size - hopefully closer to the 300KB.

The hybrid compilation model for this project was merged into the Mono project on November 1st, 2017.

Another possible method for .NET is similar to existing native code methods, and statically compiles the Mono C runtime and the developer's .NET code combined into wasm. As of this writing, a sample app using this method downloads 10 MB of code to the user's computer. For comparison, a recent full page load on Twitter.com downloaded over 7 MB of content and a recent visit to Amazon.com took 8.9 MB. According to Miguel de Icaza, the size should improve over time:

The size should come down significantly once we use a custom profile based on the mobile profile and remove many of the unnecessary features.

The project uses "the experimental WebAssembly backend of LLVM, the LLVM linker and the binaryen tooling to generate the final .wasm code", but hasn't really been updated in a couple months.

There is also prototype WebAssembly support in the official CoreRT repository.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT