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

Rewrite MarshalGeneric<T> to minimize binary size on NativeAOT #1437

Merged
merged 17 commits into from
Jan 18, 2024

Conversation

Sergio0694
Copy link
Member

@Sergio0694 Sergio0694 commented Jan 11, 2024

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:

image

@Sergio0694 Sergio0694 added performance Related to performance work trimming AOT labels Jan 11, 2024
@Sergio0694 Sergio0694 marked this pull request as ready for review January 12, 2024 20:09
@Sergio0694
Copy link
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 😄

@Sergio0694
Copy link
Member Author

Sergio0694 commented Jan 13, 2024

Checked with sizoscope, saves ~270 KB already! 🎉

image

@Sergio0694 Sergio0694 force-pushed the user/sergiopedri/trim-marshal-generic branch 2 times, most recently from 3d3ea0b to c1f9a4d Compare January 14, 2024 16:21
@Sergio0694
Copy link
Member Author

Saved another 13 KB on .NET 8, maybe a bit more on .NET 9! 🎉

image

@Sergio0694
Copy link
Member Author

Saved another 18 KB! 🎉

image

@Sergio0694 Sergio0694 merged commit 98e204b into staging/AOT Jan 18, 2024
9 checks passed
@Sergio0694 Sergio0694 deleted the user/sergiopedri/trim-marshal-generic branch January 18, 2024 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AOT performance Related to performance work trimming
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants