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

Provide trimming annotations for self-contained apps #1057

Open
yaakov-h opened this issue Nov 15, 2021 · 6 comments
Open

Provide trimming annotations for self-contained apps #1057

yaakov-h opened this issue Nov 15, 2021 · 6 comments

Comments

@yaakov-h
Copy link
Member

.NET 5 previewed the ability to trim unused code from applications and from the runtime, and .NET 6 now makes that generally available.

Relevant docs are here: https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained

Considering how many protobuf messages we ship that most apps won't use, this is quite valuable. DepotDownloader can trim about 4.5-5 MB away from SteamKit2.dll and a fully self-contained trimmed build of DD is about 15-20MB IIRC.

Related issues:

Some initial prototyping has already been done in this pull request:

@yaakov-h yaakov-h added this to the 2.4.0 milestone Nov 15, 2021
@yaakov-h yaakov-h mentioned this issue Nov 15, 2021
13 tasks
@yaakov-h
Copy link
Member Author

We may have to switch to the Google.Protobuf library which isn't reflection-based in order to (a) get this working properly, and (b) be able to run in an AOT environment such as what is being planned at the moment for .NET 7.

🤔

@xPaw
Copy link
Member

xPaw commented Oct 22, 2024

Unified messages are no longer a blocker for this, since they are fully generated without reflection.

@xPaw
Copy link
Member

xPaw commented Oct 24, 2024

With updated protobuf-net, there are still issues with properties being trimmed away:

LoggedOnCallback has this: this.ParentalSettings = Serializer.Deserialize<ParentalSettings>( ms );

ParentalSettings has public ParentalPlaytimeRestrictions playtime_restrictions { get; set; }, but after trimming only an empty class ParentalPlaytimeRestrictions is produced so it fails to deserialize it.

I tried putting the trimming attribute on messages and fields, that doesn't fix the issue: (not the exact same place, i generated it everywhere)
image

@yaakov-h
Copy link
Member Author

I did have fun problems previously with trimming and nested classes.

That said, what does "fails to deserialise" look like?

@xPaw
Copy link
Member

xPaw commented Oct 26, 2024

It's trying to call an empty constructor which does not exist, it probably would have worked if it trimmed away the entire field if no one uses it.

@mizantrop777
Copy link

mizantrop777 commented Oct 30, 2024

trimming can be disabled via

<TrimMode>link</TrimMode>
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>

...

<ItemGroup>
	<TrimmerRootDescriptor Include="ILLink.xml" />
</ItemGroup>

ILLink.xml:

<?xml version="1.0" encoding="utf-8" ?>
<linker>
  <!-- Пример сохранения всех типов в сборке -->
  <assembly fullname="Updater" preserve="all" />
  <assembly fullname="SteamKit2" preserve="all" />
  <assembly fullname="protobuf-net" preserve="all" />
  <assembly fullname="protobuf-net.Core" preserve="all" />
</linker>

@xPaw xPaw removed this from the 3.0.0 milestone Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants