-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[wasm][draft] make JSObject dynamic #78853
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsThis is exploration of crazy idea, I'm not sure I want to do it. dynamic globalThis = JSHost.GlobalThis;
Console.WriteLine("Hello from "+ globalThis.location?.href);
|
We have experimented with |
Then could we at least implement |
The problems with If we don't want anyone to ever use that part of the compiler or BCL again that makes sense, but it's kind of a shame since it might be a perfect fit for this problem. |
S.T.Json discussion was about using
I agree that it is a shame that |
These are exactly the reasons why I'm not sure this is good idea.
We could add some indirection like
I make this experiment in in light of #74233 and other similar . The alternative is generators of strongly typed proxies and dealing with type-system mismatch there. In both cases the OOP interaction would be making lot of small calls over the boundary. And both solutions will generate lot of GC traffic for both VMs. Overall the efficiency is out of window anyway. The positive aspect of making one of the "solutions" possible is that it would lower the barrier of using JS ecosystem with C# language. It will enable more people to be able to do it. At the moment people use Blazor's IJSObjectReference to achieve the same goals. |
I think there is 2 parts about performance Performance on marshalling and proxy between C# and js is felt normal and unavoidable anyway so it more likely acceptable But performance on |
I think this is actionable idea.
|
It's interesting this comes up again :) @MackinnonBuck has previously explored this area in https://github.com/aspnet/AspLabs/tree/main/src/DynamicJS, so it would be worth comparing with that, and the discussions that surround it. Mackinnon's approach takes this a little further by batching the JS operations until a .NET evaluation is required, which has pros and cons.
Yes, that sounds reasonable, especially if it goes into an external package you have to opt into, so there's a point of discovery where we can communicate details about what this is good for and what costs you need to know about.
Are there particular cases where the type system is a blocker? I would have thought that ultimately it would be better if we could provide a .NET representation of the JS browser API surface since then you get proper code completions etc rather than the pre-TypeScript experience of just hoping the developer types API names correctly. I appreciate the codegen approach is much more expensive for us to implement than mapping
That is partly why Mackinnon implemented batching (the other main reason was to make it practical for use in out-of-process scenarios like Blazor Server or WebView). However batching comes at the cost of changing exception throwing/catching semantics, which in turn was one of the main reasons we held back on the whole approach.
Technically we can make Blazor's JS interop mechanism work on Node if we want - the It's great to see experiments and ideas, @pavelsavara! |
As for me I think approach of codegen with typescript is perfect solution for giving intellisense. As the typescript already become standard for writing type definition and we could reuse whole typescript language server protocol Is it possible have an experimental branch about this feature after we have #78905 and #78906 implemented ? |
I believe that generated proxies should be more strongly typed than very dynamic approach we would use in #78905 and #78906. Sure we could have experimental branch. Feel free to give it a try @Thaina |
A But it would be nice if there was an offramp once you're done hacking to a performant API without too much rewriting. (But |
I felt I don't have enough ability to make a direct proxy without wrapping JSObject and invoke which is why I would like to wait for those first |
I don't know for sure yet. But TS is very powerful language. What you can do with generic constrains is scary to me right now. I imagine that C# version of this API would be what people really want If we do it in relaxed way, it would marshal everything as If we want to do it right, so that the generic factories to return parametrized generic proxies, it's kind of type-system rocket science to me.
I was thinking about the API which the current codegen uses. |
This is exploration of crazy idea, I'm not sure I want to do it.
Motivation: give developers easier usage of JavaScript object oriented APIs
Downsides: large downloads, GC pressure