-
Notifications
You must be signed in to change notification settings - Fork 107
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
Large DLL size increases when not setting CsWinRTAotOptimizerEnabled
to false
(WinForms, crossgen/R2R)
#1814
Comments
I agree with your feedback here. The WinRT type mappings to built-in interfaces have indeed caused more code to be generated than initially expected with respect to our generator. There are a couple of things I will be looking at doing to improve the situation here:
|
I personally would like to see a mode where it's actually opt-in instead. That is, I have to opt-in for the type to be handled at all. Realistically I will have a very small & controlled quantity of types that I want to marshal via WinRT, so I'd much prefer not having to think every time I add any type that implements IDisposable, write any delegate type, etc. about whether I should have to exclude it or not; I'd rather just add some attribute whenever I do actually want to do that (which will be easy to remember since I'm writing WinRT stuff, and also make it easy to quickly find every type that has / doesn't have the ability to be marshalled). Thanks for your consideration :) |
Posting this to hopefully help others that start seeing this. I am not certain of the OP issue, but on a relatively simple personal hobby project I am working on I started to see these error when compiling:
My C# WinForms app and libs do not explicitly use WinRT (they do pinvoke some user32.dll calls). I found dotnet/sdk#44026 and then this issue. I edited my .csproj file to add
The problem went away. I changed The problem came back. I will be leaving |
Describe the bug
After building my WinForms app and running crossgen, many of my assemblies are much larger when
CsWinRTAotOptimizerEnabled
is not set tofalse
. That source generator is emitting a lot of code that isn't needed or even used. A lot of it are theseClassNameWinRTTypeDetails
classes, and then there are these enormousGlobalVtableLookup
classes, etc.Obviously I can set
CsWinRTAotOptimizerEnabled
tofalse
and this isn't a problem for me. However, it does imply that when/if I do want/need to make use of this functionality that it has a substantial cost associated with it.If I hadn't run into a compile-time bug that's since been fixed ( dotnet/sdk#43746 ), I may not have even noticed this, or I may have attributed it to something else (crossgen codegen changes, perhaps?), or I may have spent hours and days trying to figure it out.
In addition, the
ClassNameWinRTTypeDetails
classes only seem to affect my classes that implementIDisposable
and that also happen to bepartial
, which is a strange thing to key off of. And they're all identical except for their names. This seems to be happening becauseIDisposable
is mapped toICloseable
, which is understandable. But can't these be consolidated somehow? This is an awful lot of duplicated code.I'm not using much WinRT functionality. I use some stuff from
Windows.Graphics.Display
and some more fromWindows.UI.Composition
. I subscribe to two events using delegates. This code size bloat seems really excessive to me and it would make much more sense for it to be opt-in.Here are the sizes of affected DLLs:
In total this adds 7,336 KB to my app's size if I want to use whatever this functionality is, or if I happened to not notice it. I'm not using AOT, and I'm not using trimming (at least not on these DLLs, for reasons), so it's bizarre that all this unnecessary code is being dumped into my assemblies.
Version Info
.NET 9.0-rc2, TFM of
net9.0-windows10.0.26100.0
and whatever Windows SDK, CsWinRT, etc. gets pulled in by default thereThe text was updated successfully, but these errors were encountered: