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

Size regression in Blazor WASM apps #40521

Closed
eerhardt opened this issue Mar 1, 2022 · 11 comments
Closed

Size regression in Blazor WASM apps #40521

eerhardt opened this issue Mar 1, 2022 · 11 comments
Labels
area-blazor Includes: Blazor, Razor Components Done This issue has been fixed feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly Perf
Milestone

Comments

@eerhardt
Copy link
Member

eerhardt commented Mar 1, 2022

Looking at https://aka.ms/dotnetperfstatus, there is a 140KB size regression in the default Blazor WASM app size between the following commits:

dotnet/runtime@6b83269...06228c1

SOD - New Blazor Template - Publish

image

SOD - New Blazor Template - Publish - AOT

image

We should investigate what change caused this size regression and if there is anything that can be done.

From looking at the charts, some of it comes from System.Private.CoreLib:

Before

image

After

image

But the biggest file that added here is System.Linq.Expressions.dll. It isn't in the Before, but in the After it is over 100KB itself:

After

image

Maybe a new ASP.NET change now brings in Linq.Expressions by default? cc @SteveSandersonMS @captainsafia

cc @lewing @SamMonoRT

@ghost
Copy link

ghost commented Mar 1, 2022

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

Issue Details

Looking at https://aka.ms/dotnetperfstatus, there is a 140KB size regression in the default Blazor WASM app size between the following commits:

dotnet/runtime@6b83269...06228c1

SOD - New Blazor Template - Publish

image

SOD - New Blazor Template - Publish - AOT

image

We should investigate what change caused this size regression and if there is anything that can be done.

From looking at the charts, it mostly comes from System.Private.CoreLib:

Before

image

After

image

cc @lewing @SamMonoRT

Author: eerhardt
Assignees: -
Labels:

arch-wasm, tenet-performance

Milestone: -

@pranavkm
Copy link
Contributor

pranavkm commented Mar 2, 2022

@eerhardt I'm gonna guess it's this change: #18088. We switched Blazor to use ActivatorUtilities.CreateFactory to initialize components which I can see uses System.Linq.Expressions.

@eerhardt
Copy link
Member Author

eerhardt commented Mar 3, 2022

Moving to aspnetcore, since that is what caused this regression. There isn't anything dotnet/runtime can do here.

@eerhardt eerhardt transferred this issue from dotnet/runtime Mar 3, 2022
@SteveSandersonMS
Copy link
Member

It's really great that we're able to detect this kind of thing systematically. Thanks for letting us know, @eerhardt!

@SteveSandersonMS SteveSandersonMS added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Mar 3, 2022
@mkArtakMSFT mkArtakMSFT added this to the .NET 7 Planning milestone Mar 3, 2022
@ghost
Copy link

ghost commented Mar 3, 2022

Thanks for contacting us.

We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@pranavkm
Copy link
Contributor

pranavkm commented Mar 3, 2022

@eerhardt do you think there's a way to update ActivatorUtils to ILEmit the way ServiceProvider does for apps targeting .NET Core? That would help in this case, no?

@eerhardt
Copy link
Member Author

eerhardt commented Mar 3, 2022

do you think there's a way to update ActivatorUtils to ILEmit the way ServiceProvider does for apps targeting .NET Core? That would help in this case, no?

I think that could help here. System.Text.Json is already using Reflection.Emit directly. And the Linq.Expressions code Compiling a Lambda function is already using it as well. So re-writing this code to use Ref.Emit directly would cut Linq.Expressions out of the equation.

@pranavkm
Copy link
Contributor

pranavkm commented Mar 3, 2022

We could approach it this way - I'll roll back the change citing this regression. We're on strike two because this is also a source-breaking change. I'll file a runtime issue to consider changing ActivatorUtils to use ILEmit (when possible). If that lands in 7.0 and we can verify there isn't a size regression, we'll add the change back in.

@SteveSandersonMS how does that sound?

@eerhardt
Copy link
Member Author

eerhardt commented Mar 3, 2022

Another thing to consider is dotnet/runtime#38439, and NativeAOT in general. Using Linq.Expressions allows the underlying implementation to be switched out (interpreter vs ILEmit). Where if you jump directly to ILEmit, you would need to do the switching yourself.

So we may need to check RuntimeFeature.IsDynamicCodeSupported here.

@SteveSandersonMS
Copy link
Member

[Pranav] how does that sound?

Yep, great - thanks. Rolling this change back does feel right. Maybe activation-by-default could come back in the future if the underlying implementation is updated, but it's not a big loss to tell customers they can do this themselves in user code.

@mkArtakMSFT
Copy link
Member

Closing this as we've reverted the change which contributed to this.

@mkArtakMSFT mkArtakMSFT added Done This issue has been fixed and removed untriaged labels Mar 16, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Apr 15, 2022
@amcasey amcasey added the Perf label Jun 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components Done This issue has been fixed feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly Perf
Projects
None yet
Development

No branches or pull requests

7 participants