-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[draft] JavaScript interop via [JSImport] and [JSExport] #41665
Conversation
060bdad
to
00b6e5f
Compare
@pavelsavara what is the state of this change? Is this ready for us to review already? |
I will start working on it as soon as we land the preview7 SDK of the runtime in this repo. |
099b6b6
to
328ac79
Compare
… `[JSExport]` - simplified interop for: Navigation, console logging, `JSInProcessObjectReference` dispose, `WebAssemblyHostBuilder`, `RegisteredComponentsInterop` - lazy assembly loading, satelite assembly loading: I changed it to deal with each file as separate interop call. Marshaling nested arrays of managed objects is not supported anymore. - `DefaultWebAssemblyJSRuntime.InvokeDotNet` - I think there could be follow up work which will make buffers transfer easier. - `WebAssemblyJSRuntime.InvokeJS` - I think there could be follow up work which will make buffers transfer easier. I don't fully understand the goal of `BeginInvoke`, `EndInvoke`. Note we support Task/Promise marshaling now. - `WebAssemblyRenderer` - this was GC hazzard as stays GC hazzard, the change is not making it more risky. It would be interesting to see if there is any perf impact. I hope it's faster. - `WebAssemblyHotReload` - I simplified dynamic import - `GlobalExports.ts` - I added few missing and few new methods. Those starting with upper case letter are `[JSExport]` bound managed methods, with JS native paramater types. - made `IJSUnmarshalledObjectReference` and `IJSUnmarshalledRuntime` obsolete - `[JSImport]` and `[JSExport]` are static method and they are not on class which could be mocked anymore. I commented 2 tests which relly on it. Leaving it for Blazor team to take next steps. - Added COOP headers to the sample app, so that subtle crypto could be tested
5e7694d
to
51992df
Compare
Regarding perf, I ran the Blazor WebAssembly perf benchmarks and found that this PR didn't really change the numbers in a conclusive way. That's great, since the worry was regression - this change isn't meant to improve perf for the existing code which largely relies on unmarshalled interop. In a few of the test cases, this PR may be associated with about a 2% slowdown but it doesn't happen consistently and isn't far outside the margin of experimental error. Since the .NET-on-WebAssembly runtime itself has become generally faster in various ways in .NET 7 (both interpreted and AOT), I'm confident that people are still going to find the upgrade to .NET 7 to be a perf win. |
Closing in favor of smaller #42814 |
Hi @pavelsavara. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
I would love to re-open this for Net8 with your assistance on broken tests. |
Hi @pavelsavara. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Definitely. Even though we will need to leave the obsoleted unmarshalled interop APIs in place until after the next LTS release, we can stop using them in Blazor. Thanks for pushing this whole area forwards. |
I realized that I could add bit of explanations:
|
Hi @pavelsavara. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Changes
[JSImport]
and[JSExport]
JSInProcessObjectReference
dispose,WebAssemblyHostBuilder
,RegisteredComponentsInterop
DefaultWebAssemblyJSRuntime.InvokeDotNet
- I think there could be follow up work which will make buffers transfer easier.WebAssemblyJSRuntime.InvokeJS
- I think there could be follow up work which will make buffers transfer easier. I don't fully understand the goal ofBeginInvoke
,EndInvoke
. Note we support Task/Promise marshaling now.WebAssemblyRenderer
- this was GC hazzard as stays GC hazzard, the change is not making it more risky. It would be interesting to see if there is any perf impact. I hope it's faster.WebAssemblyHotReload
- I simplified dynamic importGlobalExports.ts
- I added few missing and few new methods. Those starting with upper case letter are[JSExport]
bound managed methods, with JS native paramater types.IJSUnmarshalledObjectReference
andIJSUnmarshalledRuntime
obsolete[JSImport]
and[JSExport]
are static method and they are not on class which could be mocked anymore. I commented 2 tests which relly on it. Leaving it for Blazor team to take next steps.Testing
Risks