Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

MichalStrehovsky
Copy link
Member

This is the same issue as e.g. #84206. The compiler needs to consider delegate Invoke methods always reflectable because of trimming warning suppressions around this in the framework. But that means the compiler is going to create type loader templates for all types in the Invoke signature. If one of those is a ValueTuple, it will root the ability to runtime-create arbitrary comparers at runtime (ValueTuple annoying implements Equals using EqualityComparer.Default) and with it the entire type loader.

For a sample app in #82607 this causes about 200 kB of bloat to be generated (more than 10% of the app size).

Closes #82607.

This is the same issue as e.g. dotnet#84206. The compiler needs to consider delegate Invoke methods always reflectable because of trimming warning suppressions around this in the framework. But that means the compiler is going to create type loader templates for all types in the `Invoke` signature. If one of those is a `ValueTuple`, it will root the ability to runtime-create arbitrary comparers at runtime (`ValueTuple` annoying implements `Equals` using `EqualityComparer.Default`) and with it the entire type loader.

For a sample app in dotnet#82607 this causes about 200 kB of bloat to be generated (more than 10% of the app size).
@ghost
Copy link

ghost commented Jun 5, 2023

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Issue Details

This is the same issue as e.g. #84206. The compiler needs to consider delegate Invoke methods always reflectable because of trimming warning suppressions around this in the framework. But that means the compiler is going to create type loader templates for all types in the Invoke signature. If one of those is a ValueTuple, it will root the ability to runtime-create arbitrary comparers at runtime (ValueTuple annoying implements Equals using EqualityComparer.Default) and with it the entire type loader.

For a sample app in #82607 this causes about 200 kB of bloat to be generated (more than 10% of the app size).

Closes #82607.

Author: MichalStrehovsky
Assignees: MichalStrehovsky
Labels:

area-System.Threading

Milestone: -

@omariom
Copy link
Contributor

omariom commented Jun 5, 2023

The code generated by Roslyn for records and anonymous types uses EqualityComparer too, even for IEquatables and the well-known primitives.

@MichalStrehovsky
Copy link
Member Author

The code generated by Roslyn for records and anonymous types also uses EqualityComparer, even for IEquatables and the well-known primitives.

This is known - we recommend everyone who cares about the size impact not to use them unless they really need all the provided features (equality, hashcode, stringification, etc.) - they're going to pay for those even when they don't use them: dotnet/aspnetcore#45604 (comment)

@stephentoub stephentoub merged commit 29401b3 into dotnet:main Jun 5, 2023
@MichalStrehovsky MichalStrehovsky deleted the syncctx branch June 5, 2023 21:25
@ghost ghost locked as resolved and limited conversation to collaborators Jul 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NAOT publish build has a 1MB size delta between reflection free and not (+50% total size)
3 participants