Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor performance

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.js, 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 aren't any comparisons of the performance of popular JavaScript frameworks. So I would like to know the theoretical performance of the new framework from Microsoft.

like image 880
FoxPro Avatar asked May 19 '18 06:05

FoxPro


1 Answers

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 CDNs for Blazor applications will do the trick.

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

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

You can create a small Blazor application and run it in Firefox, Chrome or Edge. In most cases, Firefox runs Blazor applications much faster than Chrome or Edge, which implies that browser makers still need to improve, and even Firefox can improve.

If your application needs to access the DOM frequently, then definitely WebAssembly / Blazor will be slower compared to any JavaScript libraries since WebAssembly can’t directly access the DOM without using Invokes (which is slow at the moment. Please refer my Blazor benchmark below).

On Firefox, 10,000 RegisteredFunction.InvokeUnmarshalle calls to empty methods takes 250 ms while Chrome and Edge need more than 2400 ms in my PC. In pure JavaScript it takes below 10 milliseconds for the same scenario.

Additionally, the current implementation of Blazor has its own MSIL engine on top of the browser's WebAssembly 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 released. Once it's released, Blazor will be much faster than the current implementation.

Mono and WebAssembly - Updates on Static 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 WebAssembly maintainers, browser developers, Microsoft and the communities to make the theories practical.

Update 10th July 2018

There are new proposals in the WebAssembly repositories.

  1. Allowing WebAssembly to handle DOM directly. Interface types #8

  2. Reference Types for WebAssembly with GC. Reference Types for WebAssembly

The above two proposals will pave the path to much faster interaction between the DOM and WebAssembly in the future. In other words, Blazor will be much faster in the future.

Update 17 October 2018

The Firefox team was able to reach a JavaScript-to-WebAssembly call as fast as JavaScript-to-JavaScript method calls. As of now Firefox is far ahead of any other browsers when it comes to WebAssembly support.

Calls between JavaScript and WebAssembly are finally fast

like image 98
VibeeshanRC Avatar answered Sep 21 '22 06:09

VibeeshanRC