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

Blazor WASM apps should fully trim Microsoft.Extensions.* assemblies #24634

Closed
eerhardt opened this issue Aug 6, 2020 · 4 comments
Closed

Blazor WASM apps should fully trim Microsoft.Extensions.* assemblies #24634

eerhardt opened this issue Aug 6, 2020 · 4 comments
Assignees
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
Milestone

Comments

@eerhardt
Copy link
Member

eerhardt commented Aug 6, 2020

Today, when publishing a Blazor WASM app, we are telling the ILLinker to trim Microsoft.Extensions.* assemblies, but only at a "type granularity" level. Meaning, if some part of the Type is used, preserve the whole Type.

<_BlazorTypeGranularAssembly
Include="@(ManagedAssemblyToLink)"
Condition="'%(Extension)' == '.dll' AND ($([System.String]::Copy('%(Filename)').StartsWith('Microsoft.AspNetCore.')) or $([System.String]::Copy('%(Filename)').StartsWith('Microsoft.Extensions.')))">
<Required>false</Required>
<Preserve>all</Preserve>
</_BlazorTypeGranularAssembly>

This causes unnecessary bloat in the produced app because there are types in Microsoft.Extensions.* where some unused code is pulling in more System.* assemblies (e.g. System.Diagnostics.DiagnosticSource.dll), causing even more unused code to be compiled in the app.

With the recent work done in Extensions to make them linker-friendly:

we should be able to remove the "type granularity" clauses for these assemblies now that they are linker safe.

Using a recent rc1 build, I'm seeing the following size savings in IL:

Uncompressed IL Compressed IL (.br)
master 2,426,368 bytes 852,236 bytes
PR 2,339,328 bytes 822,834 bytes
Difference 87,040 bytes (85 KB) 29,402 bytes (28.7 KB)

cc @SteveSandersonMS @pranavkm @marek-safar

@pranavkm pranavkm self-assigned this Aug 6, 2020
@pranavkm pranavkm added this to the 5.0.0-rc1 milestone Aug 6, 2020
@javiercn javiercn added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Aug 7, 2020
@SteveSandersonMS
Copy link
Member

Thanks @eerhardt!

@samsp-msft
Copy link
Member

Once complete, does this mean that the Microsoft.AspNetCore.* and Microsoft.Extensions.* assemblies should just get standard TrimMode=Trim behavior?

@eerhardt
Copy link
Member Author

eerhardt commented Aug 10, 2020

My thinking is that only Microsoft.Extensions.* assemblies will get the standard TrimMode=Trim behavior to start with. We've done the work to ensure they are linker-safe. I don't think anyone has done the work to make all the Microsoft.AspNetCore.* assemblies to be linker-safe. @davidfowl has started on some of the server side assemblies, but I don't think the Blazor WASM assemblies have been made linker-safe yet.

ghost pushed a commit that referenced this issue Aug 19, 2020
* Enable trimming for Microsoft.Extensions packages

Fixes #24634

* Update Microsoft.NET.Sdk.BlazorWebAssembly.csproj

* Apply suggestions from code review

* Fixup test
@pranavkm pranavkm added Done This issue has been fixed and removed Working labels Aug 19, 2020
@davidfowl
Copy link
Member

Nice!

@ghost ghost locked as resolved and limited conversation to collaborators Sep 18, 2020
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
Projects
None yet
Development

No branches or pull requests

6 participants