rocksdanister / weather

Windows native weather app powered by DirectX12 animations
https://rocksdanister.com/weather
MIT License
431 stars 22 forks source link

Enable trimming #4

Open rocksdanister opened 11 months ago

rocksdanister commented 11 months ago

From Default.rd.xml remove: <Assembly Name="Application" Dynamic="Required All" />

Have to rewrite using DI source generator: https://github.com/CommunityToolkit/Labs-Windows/discussions/463

Other MSBuild options you can set in your .csproj/.props to save size:

<DisableStackTraceMetadata>true</DisableStackTraceMetadata>
<DisableExceptionMessages>true</DisableExceptionMessages>

First one should save ~8% of binary size Second one can save a few hundred KBs (this is all per CPU arch)

rocksdanister commented 11 months ago

Early test shows upto 50% reduction (50mb -> 25mb) with the following Default.md file:

    <!--<Assembly Name="*Application*" Dynamic="Required All" />-->

    <!-- .NET Native fix -->
    <Assembly Dynamic="Required All" Name="NLog"/>
    <Assembly Dynamic="Required All" Name="Microsoft.Extensions.DependencyInjection"/>
    <Assembly Dynamic="Required All" Name="Microsoft.Extensions.Options"/>
    <Assembly Dynamic="Required All" Name="Microsoft.Extensions.Logging"/>
    <Assembly Dynamic="Required All" Name="Microsoft.Extensions.Http"/>

Problem is serializers returning null due to reflection, will need to rewrite using source generator: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation

I was suggested to use System.Text.Json 8.0 Preview 1 for better source generators.

Sample:

[JsonSourceGenerationOptions(PropertyNameCaseInsensitive = true)]
[JsonSerializable(typeof(AirQuality), GenerationMode = JsonSourceGenerationMode.Metadata)]
internal partial class MyJsonContext : JsonSerializerContext
{
}
..
await JsonSerializer.DeserializeAsync(stream, MyJsonContext.Default.AirQuality);