Rewrite MarshalGeneric<T> to minimize binary size on NativeAOT#1437
Merged
Conversation
Member
Author
|
Publishing this, as I think it's in a decent state now and covering almost all scenarios. There's just one unit test that's failing only on .NET Core 3.1 for some reason, @manodasanW if you can I'd love a second pair of eyes on that whenever you have time 😄 |
Member
Author
3d3ea0b to
c1f9a4d
Compare
Member
Author
Member
Author
0b2067b to
668af76
Compare
manodasanW
reviewed
Jan 18, 2024
manodasanW
approved these changes
Jan 18, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



This PR completely rewrites
MarshalGeneric<T>, to reduce the binary size. Currently there's over 200 KB just in delegate size coming from various generic instantiations for this class alone. Probably much more if we consider all the rest of the code. This PR changes the structure of the class to use a static constructor where we do trimmable type switches and also optimize for lots of well known cases for primitive types and other ABI types that we know will always get constructed. Additionally, I've also introduced a much more compact system of constructing delegates for the various generated methods on the helper types coming from the generated projections, which also skip all those generated closures.Here's what sizoscope is showing on a minimal WinRT component, for reference: