Blazor performance

FoxPro picture FoxPro · May 19, 2018 · Viewed 22.3k times · Source

I would like to start using Blazor, despite the fact that it is still at the alpha level.

As I understand it, Blazor uses WebAssembly to compile C# on the client side.

And I have these questions:

Does this approach run faster than, for example, React / Vue, compiled in JavaScript?

Is it true that the browser will need to download the WebAssembly library every time the page loads?

On the Internet there are no comparisons of the performance of popular JS frameworks. So I would like to know the theoretical performance of the new framework from Microsoft. Thank you in advance.

Answer

VibeeshanRC picture VibeeshanRC · May 19, 2018

Is it true that the browser will need to download the Webassembly library every time the page loads?

No, browsers can cache the files. Common CDN for Blazor apps will do the trick.

Is this system faster to work than, for example, React / Vue, compiled in JavaScript?

Blazor uses web assembly, On paper web assembly should be faster than any js library, however not all browsers have a mature web assembly parser yet. So you might find that browsers will not run web assembly in an optimal speed as of now.

You can create a small blazor app and run it in Firefox, chrome or edge. In most cases Firefox runs blazor apps much faster than chrome or edge, which implies that browser makers still need to improve, even Firefox can improve.

If your app needs to access DOM frequently, then definitely web assembly / Blazor will be slower compared to any JS libraries since web assembly can’t directly access DOM without using Invokes (Which is slow at the moment, please refer my blazer benchmark below).

On Firefox 10,000 RegisteredFunction.InvokeUnmarshalle calls to empty methods takes 250ms while chrome and edge need more than 2400ms in my PC.’ In pure JS it takes below 10 millisonds for the same scenario.

Additionally, current implementation Blazor has its own MSIL engine on top of the browsers web assembly Engine, which means there are two interpreters working to run a Blazor project, Like two translators interpreting a conversation instead on one. Currently Microsoft is working on an AOT compiler, which is not yet release. Once its release Blazor will be much faster than the current implementation.

http://www.mono-project.com/news/2018/01/16/mono-static-webassembly-compilation/

We can safely assume that the web assembly is the future of web development, but at the moment we can’t say anything about Blazor’s future. On paper Blazor can be faster than any framework out there, however we need commitment from web assembly maintainers, Browser developers, Microsoft and the communities to make the theories practical.

Update 10th July 2018

There are new proposals in the WebAssembly repos.

  1. Allowing WebAssembly handle DOM directly. https://github.com/WebAssembly/proposals/issues/8

  2. Reference Types for WebAssembly with GC. https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md

Above two proposals will pave path to much faster interaction between DOM and webassembly in the future. IOW Blazor will be much faster in the future.

Update 17 October 2018

Firefox team was able to reach JS -> WASM call as fast as JS -> JS method calls. As of now FireFox is far ahead of any other browsers when it comes to WebAssembly support

https://hacks.mozilla.org/2018/10/calls-between-javascript-and-webassembly-are-finally-fast-%F0%9F%8E%89/