MauiHybridWebView icon indicating copy to clipboard operation
MauiHybridWebView copied to clipboard

JSInterop performance vs Blazorwebview

Open orosbogdan opened this issue 1 year ago • 1 comments
trafficstars

In regards to my question here https://github.com/dotnet/maui/issues/13551, I'm trying to get a better performance while transfering arrays of objects from javascript to c# and from c# to javascript, so far I did it only with the blazorwebview that MAUI blazor hybrid offers and it's pretty slow (probably because of JSON serialization?).

I understand that IJSUnmarshalledRuntime is deprecated and the JSImport attribute is applicable only to webassembly.

Would this hybridwebview be able to host a website made with blazor webassembly ? If so would the performance for the js interop in case of arrays of objects being transfered be improved ?

orosbogdan avatar Jul 04 '24 20:07 orosbogdan

Hi @orosbogdan , in theory it should definitely be possible to host a Blazor WASM app in HybridWebView because it doesn't particularly 'care' what code it's hosting. You might be the first one to try it!

Regarding perf:

  1. In BlazorWebView in most cases there shouldn't need to be a lot of marshalling between the C# world and JS world because most app logic that deals with large datasets is entirely in C#, and can simply 'share' memory (e.g. via services, global statics, etc.).
  2. In cases where there is a need to transfer large amounts of data between C# and JS we'd have to look at the particular case where the performance is bad. On many platforms the native WebView controls used by HybridWebView/BlazorWebView offer more advanced ways to share data between those two worlds. While they are not directly exposed by the controls, it might be possible to access those mechanisms in app-specific code.
    • For example, on Windows the WebView2 control is used, which has this functionality: https://learn.microsoft.com/microsoft-edge/webview2/how-to/communicate-btwn-web-native
    • (I haven't tried it out yet, so I'm not familiar with its usage or perf characteristics, but it could be part of a solution).

Eilon avatar Jul 20 '24 00:07 Eilon