Skip to content
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

Epic: Expand .NET WebAssembly Capabilities #43767

Closed
5 of 8 tasks
Tracked by #5366
marek-safar opened this issue Oct 23, 2020 · 18 comments
Closed
5 of 8 tasks
Tracked by #5366

Epic: Expand .NET WebAssembly Capabilities #43767

marek-safar opened this issue Oct 23, 2020 · 18 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-Meta Epic Groups multiple user stories. Can be grouped under a theme. Priority:0 Work that we can't release without
Milestone

Comments

@marek-safar
Copy link
Contributor

marek-safar commented Oct 23, 2020

We shipped the first fully .NET Core based version of WebAssembly for Blazor in .NET 5. We had to make a few compromises and cut several features to meet the deadline. One of the major features postponed from .NET 5 was AOT support for WebAssembly. We want to keep investing and improving WebAssembly support to make our .NET solutions on the web complete and competitive.

Goals

Native WebAssembly / AOT Support

We have customer evidence and have done our performance measurements of Blazor scenarios. In several areas, there is a large gap between client and server performance which limits the potential of the .NET WebAssembly platform to be used for a broader range of applications. We have improved performance for several scenarios in .NET 5 release but many of them remain to be much slower compared to our server implementation or JavaScript frameworks.

Web Cryptographic Support

The .NET APIs have been designed with the desktop mindset first. For that reason, we had to make few critical APIs not supported when running .NET inside the browser in .NET 5 release and made libraries like Azure Cosmos DB which need cryptographic support to do add extra compatibility code to work inside the browser. We need to revisit that decision as it makes the migration between server and client Blazor more complicated and adds fragmentation angle to .NET ecosystem. We will focus on bringing cryptography support to WebAssembly in the way it's compatible with other .NET workloads.

Smaller Globalization Dependencies

Globalization libraries typically add significant size to applications. Globalization invariant mode enables developers to ships smaller apps, but offers essentially no globalization support at all. Globalization invariant mode could offer more functionality, with a fraction of the size required. We’ve talked about doing this for Wasm and Docker. We need to determine if we can decide a cluster of globalization functionality that solves customer problems and that appeals to at least some regions.

General App Size Reduction

In Blazor scenario reducing app size in every new version is equally important to the developers as the performance improvements we make. We regressed the final size for most of these apps in .NET 5 compared to Blazor 3.2. In the next release, we are aiming to reduce the final compressed size for typical Blazor workloads by at least 20%. We'll need to keep in mind that if we enable AOT support for wasm by default in, the size is likely going to grow not to shrink and more mitigations will need to be put in place.

Unmarshalled interop

When running on Blazor WebAssembly, it's possible to make unmarshalled calls from .NET to JavaScript. These are synchronous calls that don't perform JSON serialization of arguments or return values. All aspects of memory management and translations between .NET and JavaScript representations are left up to the developer. While using unmarshalled interop has the least overhead of the JavaScript interop approaches, the JavaScript APIs required to interact with these APIs are currently undocumented and not officially supported. Various users have reported that these APIs are absolutely required to satisfy their requirements. For .NET 6 we will finalize these APIs and document unmarshalled interop as a supported feature.

Users Stories

@marek-safar marek-safar added the User Story A single user-facing feature. Can be grouped under an epic. label Oct 23, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Oct 23, 2020
@lewing lewing added untriaged New issue has not been triaged by the area owner and removed untriaged New issue has not been triaged by the area owner labels Oct 24, 2020
@cathysull cathysull added the Priority:0 Work that we can't release without label Oct 30, 2020
@samsp-msft
Copy link
Member

Can we add Blazor to the title?

@danmoseley
Copy link
Member

@marek-safar should make each of the sub issues into User Stories so they can get individual costs and maybe priorities.

@marek-safar
Copy link
Contributor Author

@samsp-msft WebAssemly != Blazor so I'd keep it this way as it has a broader impact.

@danmosemsft I think it'd be better to make this item Epic

@danmoseley
Copy link
Member

@marek-safar fine, but I think it needs child user stories - I don't see how we can cost this as a whole.

@danmoseley
Copy link
Member

@danroth27 are you the PM for this one?

@danroth27
Copy link
Member

@danmosemsft Yup

@marek-safar marek-safar added Epic Groups multiple user stories. Can be grouped under a theme. and removed User Story A single user-facing feature. Can be grouped under an epic. untriaged New issue has not been triaged by the area owner labels Nov 5, 2020
@marek-safar marek-safar changed the title User Story: Expand .NET WebAssembly Capabilities Epic: Expand .NET WebAssembly Capabilities Nov 5, 2020
@ghost
Copy link

ghost commented Nov 6, 2020

Tagging subscribers to this area: @CoffeeFlux
See info in area-owners.md if you want to be subscribed.

@samsp-msft
Copy link
Member

Changed the link for the Blazor source generators as it was moved to aspnetcore repo.

@RChrisCoble
Copy link

RChrisCoble commented Nov 18, 2020

Given the Epic's top description of improving performance compared to backend execution .Net Core performance, I'm somewhat surprised you're not doing work to enable this in Blazor: (or maybe you are and I'm missing it?)

Real multithreading (on supported browsers) #17730

@danroth27
Copy link
Member

@RChrisCoble Much of the work to support multithreading in .NET on WebAssembly has been done, but browser support still isn't fully available. Safari in particular hasn't reenabled support for shared array buffers yet. How useful is multithreading support for your scenarios if it only worked in Chromium based browsers, and not Safari?

@RChrisCoble
Copy link

@RChrisCoble Much of the work to support multithreading in .NET on WebAssembly has been done, but browser support still isn't fully available. Safari in particular hasn't reenabled support for shared array buffers yet. How useful is multithreading support for your scenarios if it only worked in Chromium based browsers, and not Safari?

I replied to your Microsoft email directly for this response, as it requires divulging future release dates and intended scope.

Thanks for the follow up, greatly appreciated!

@joperezr joperezr added this to the 6.0.0 milestone Feb 9, 2021
@plaisted
Copy link

plaisted commented Mar 9, 2021

This may be outside scope but would love the ability to interop in some way to WASM from .net code (all of the above goals are really targeting scenarios where .net code is running in a WASM environment). There are some community projects out there experimenting with this this through WASM->CIL conversion. Since many languages now compile to WASM it would make importing JS / Rust / Go / etc libraries possible with some work.

@jeromelaban
Copy link
Contributor

@plaisted this is already possible: https://jaylee.org/archive/2020/03/22/csharp-interop-with-c-cpp-and-rust-in-webassembly.html, through p/invoke. This is what SkiaSharp uses, same for SQLitePCL.

@plaisted
Copy link

plaisted commented Mar 9, 2021

I was under the impression that only worked when running in a mono webassembly environment... I'll dig in again and take a look. My suggestion was to be able to effectively P/Invoke a WASM binary while running under net core (or transpile it to a DLL ahead of time and then import as normal).

@jeromelaban
Copy link
Contributor

jeromelaban commented Mar 10, 2021

It's running as well in a net6 environment, though the current tooling in main does not allow for it. I added that support in the uno wasm bootstrapper and it works for both mono/mono and dotnet/runtime.

@ChristianWeyer
Copy link

ChristianWeyer commented Mar 10, 2021

Thanks for the link and the article @jeromelaban - did you ever get to write the follow-up "how to use strings back and forth in both environments"?

@jeffhandley jeffhandley added the arch-wasm WebAssembly architecture label Aug 11, 2021
@ghost
Copy link

ghost commented Aug 11, 2021

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

We shipped the first fully .NET Core based version of WebAssembly for Blazor in .NET 5. We had to make a few compromises and cut several features to meet the deadline. One of the major features postponed from .NET 5 was AOT support for WebAssembly. We want to keep investing and improving WebAssembly support to make our .NET solutions on the web complete and competitive.

Goals

Native WebAssembly / AOT Support

We have customer evidence and have done our performance measurements of Blazor scenarios. In several areas, there is a large gap between client and server performance which limits the potential of the .NET WebAssembly platform to be used for a broader range of applications. We have improved performance for several scenarios in .NET 5 release but many of them remain to be much slower compared to our server implementation or JavaScript frameworks.

Web Cryptographic Support

The .NET APIs have been designed with the desktop mindset first. For that reason, we had to make few critical APIs not supported when running .NET inside the browser in .NET 5 release and made libraries like Azure Cosmos DB which need cryptographic support to do add extra compatibility code to work inside the browser. We need to revisit that decision as it makes the migration between server and client Blazor more complicated and adds fragmentation angle to .NET ecosystem. We will focus on bringing cryptography support to WebAssembly in the way it's compatible with other .NET workloads.

Smaller Globalization Dependencies

Globalization libraries typically add significant size to applications. Globalization invariant mode enables developers to ships smaller apps, but offers essentially no globalization support at all. Globalization invariant mode could offer more functionality, with a fraction of the size required. We’ve talked about doing this for Wasm and Docker. We need to determine if we can decide a cluster of globalization functionality that solves customer problems and that appeals to at least some regions.

General App Size Reduction

In Blazor scenario reducing app size in every new version is equally important to the developers as the performance improvements we make. We regressed the final size for most of these apps in .NET 5 compared to Blazor 3.2. In the next release, we are aiming to reduce the final compressed size for typical Blazor workloads by at least 20%. We'll need to keep in mind that if we enable AOT support for wasm by default in, the size is likely going to grow not to shrink and more mitigations will need to be put in place.

Unmarshalled interop

When running on Blazor WebAssembly, it's possible to make unmarshalled calls from .NET to JavaScript. These are synchronous calls that don't perform JSON serialization of arguments or return values. All aspects of memory management and translations between .NET and JavaScript representations are left up to the developer. While using unmarshalled interop has the least overhead of the JavaScript interop approaches, the JavaScript APIs required to interact with these APIs are currently undocumented and not officially supported. Various users have reported that these APIs are absolutely required to satisfy their requirements. For .NET 6 we will finalize these APIs and document unmarshalled interop as a supported feature.

Users Stories

Author: marek-safar
Assignees: marek-safar, danroth27
Labels:

Epic, arch-wasm, area-Meta, Priority:0

Milestone: 6.0.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Meta Epic Groups multiple user stories. Can be grouped under a theme. Priority:0 Work that we can't release without
Projects
No open projects
Development

No branches or pull requests