Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need Blazor Wasm Performance Improvement on CPU Intensive Calculations

I have a c# WinForms app that I have been converting to Blazor Wasm. It needs to perform a set cpu-intensive calculations (i.e. no IO or UI interaction) after most user inputs. The calculations entail repetitively (30-50 times) invoking a number of methods in a set of 25-35 C# class objects depending on the scenario. The same calculation code runs in the WinForms and Blazor apps.

I am seeing a ~20 fold degradation in performance under Blazor (e.g. 350ms in WinForms vs 7000ms in Blazor). Does that level of degradation make sense? Is a big part of it inherent to running within a browser? Is Blazor Wasm a big part of it somehow? I have confirmed that the degradation is spread across the calculations, not in isolated spots. Are there any ways to significantly reduce the degradation? The objects that perform the calculations could be put in a class library if that might help for some reason.

I have posted this question in the AspNetCore Discussions in GitHub, but have had no responses. I am using VS Community 2019 v16.8.2, AspNetCore 5.0, and Chrome v

Thanks. Steve

like image 467
Steve Rehling Avatar asked Nov 28 '20 17:11

Steve Rehling


People also ask

Why is Blazor not popular?

Blazor projects are slow on the client-side because you have to download the entire dot net runtime along with the necessary DLL libraries on your browser. Additionally, Blazor apps have latency issues.

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 .

Should I learn Blazor 2022?

The framework enables developers to build interactive and reusable web UI in existing web technologies like C# or HTML. When it comes to grammar and syntax, the framework allows developers to use the ones of Razor and C#. Even though Blazor has accumulated only 9k+ starts on GitHub, it's still worth considering.


1 Answers

This is a very late response to this question, but would web workers help to resolve this issue? This should bring some multi-threaded capability to the table. I can't speak to implementing this myself, but here's one helper library that appears to bring this into Blazor fairly easily:

https://github.com/Tewr/BlazorWorker

In native JavaScript you can access the core count of the browser through the Navigator Api:

const coreCount = window.navigator.hardwareConcurrency;
console.log(`Your computer has ${coreCount} cores!`);
like image 197
GenericUser Avatar answered Oct 02 '22 20:10

GenericUser