'Is there a way in Blazor to reverse map wasm-function(#) back to the c# method?

I am running a Blazor page on Chrome and I see from the Chrome profiler that it is spending a lot of time in the code wasm-function(633). Is there any way for me to tell what c# code this corresponds to?

I want to improve the performance of the page and it would help to know what is causing the slow performance before changing any code.

I know that Blazor performance is not good compared to javascript etc., but I also have seen with limited experiments that some C# techniques perform better than others. I was just looking for a data-driven way to find where my slow points are.



Solution 1:[1]

You can use WasmEmitSymbolMap property which allows to generates a dotnet.js.symbols file during compilation where you will find C# method to which wasm-function(633) corresponds to.

Another way is to use WasmNativeStrip property. By setting it false you will have C# method names not stripped. Please note that it can be only used in AOT compiled mode and it will increase dotnet.wasm size significantly.

enter image description here

<PropertyGroup>
  ...
  <WasmEmitSymbolMap>true</WasmEmitSymbolMap>
  <WasmNativeStrip>false</WasmNativeStrip>
  ...
</PropertyGroup>

You can find full list of properties here - https://github.com/dotnet/runtime/blob/main/src/mono/wasm/build/WasmApp.targets

Solution 2:[2]

Sadly, I think that it is not possible, yet, to trace wasm function calls back to c# code. Blazor uses the Mono runtime which has been compiled to wasm. The wasm functions are really mono runtime code not my C# code.

My c# code is compiled to Intermediate Language (IL) which runs inside mono. I probably need to looks for a future Blazor profiler or a mono profiler that can compile to wasm to get what I was looking for.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mike Wodarczyk
Solution 2 Mike Wodarczyk