Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce the size of dll/wasm compiled by aspnet/blazor?

I notice that the file size of *.wasm compiled by Rust is acceptable . However , a minimal HelloWorld compiled by AspNet/Blazor will take up almost 2.8MB .

mono.wasm       1.75MB
mscorlib.dll    1.64MB
*.dll           ....

If I understand correctly , the mono.wasm is the VM that runs in browser and runs the dll we write . Does that mean no matter what we do , we cannot make the size of files less than 1.75MB ? If not , is there a way to reduce the file size ?

like image 378
itminus Avatar asked Oct 05 '18 01:10

itminus


People also ask

Is Blazor Wasm multithreaded?

NET apps on WebAssembly using Web Workers," Microsoft said today. "This is a new . NET runtime capability. Multithreading support hasn't been integrated yet into Blazor WebAssembly apps (planned for .

How do I clear Blazor WebAssembly cache?

Just press Ctrl+F5 it cleans cache and gets files again.

How big is the Blazor runtime?

But in addition to the JavaScript, the Blazor app also loads the . NET runtime in WebAssembly format (622kB) and all the framework DLLs, 3rd party DLLs, and our DLLs (together ~3MB).

Does Blazor compile to WebAssembly?

Blazor WebAssembly supports ahead-of-time (AOT) compilation, where you can compile your . NET code directly into WebAssembly. AOT compilation results in runtime performance improvements at the expense of a larger app size.


1 Answers

Yes, 2.8 MBytes is quite a large payload for a 'Hello World' applications. However, Blazor is still very much an experimental technology, which is not ready for production use yet. There are numerous reasons why the generated output is so large at the moment:

Your current application runs in an interpreted mode, where the mono.wasm file ships the CLR to your browser, allowing it to execute your DLL. A faster, and more size efficient approach would be to use Ahead of Time Compilation (AOT) as described in this article. This would allow the compiler to strip out any library functions that are not used, giving a highly optimised output.

The features of the WebAssembly runtime itself are quite limited, future version will add garbage collection and various other capabilities that Blazor will be able to use directly. At the moment mono.wasm includes its own garbage collector.

The Blazor project itself has a number of open issues describing various optimisations which are being actively worked on. It already performs tree-shaking and various other optimisations, but this type of work takes time.

like image 155
ColinE Avatar answered Oct 08 '22 05:10

ColinE