BT

Your opinion matters! Please fill in the InfoQ Survey!

.NET WebAssembly Support an Ongoing Experiment

| by David Iffland Follow 3 Followers on Dec 05, 2017. Estimated reading time: 2 minutes |

A note to our readers: As per your request we have developed a set of features that allow you to reduce the noise, while not losing sight of anything that is important. Get email and web notifications by choosing the topics you are interested in.

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 Stage
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.

Tell us what you think

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

Email me replies to any of my messages in this thread
Community comments

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

Email me replies to any of my messages in this thread

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

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT