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

Enable trimming #4

Open
rocksdanister opened this issue Sep 26, 2023 · 1 comment
Open

Enable trimming #4

rocksdanister opened this issue Sep 26, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@rocksdanister
Copy link
Owner

rocksdanister commented Sep 26, 2023

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

Have to rewrite using DI source generator:
CommunityToolkit/Labs-Windows#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 rocksdanister added the enhancement New feature or request label Sep 26, 2023
@rocksdanister
Copy link
Owner Author

rocksdanister commented Sep 28, 2023

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant