-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
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.
Lines 372 to 377 in 6c35e2e
| <_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:
- Annotate DependencyInjection to make it linker friendly runtime#40227
- Annotate Extensions.Options to make it linker friendly runtime#40294
- Make Extensions linker friendly. runtime#40431
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) |