Skip to content

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

@eerhardt

Description

@eerhardt

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

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedarea-blazorIncludes: Blazor, Razor Componentsfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssembly

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions