-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Note
Follow up to #82607
Overview
I'm experimenting with NativeAOT to create self-contained native shared libraries using ComputeSharp that can be used by native applications (or other native libraries). I'm currently using sizoscope to go through everything's causing binary size increase and trying to address them. After having found and fixed the two main issues I had there (one Regex use, and Type.GUID pulling in a bunch of garbage), I'm left with what I think is pretty much as minimal as I can reasonably be the library to be, and it all works with reflection disabled as well (as it's not really using reflection anywhere either). But, I'm noticing quite a big size delta when trying with reflection free to get another comparison point.
| Reflection disabled | Binary size |
|---|---|
| No | 1030 KB |
| Yes | 830 KB |
Delta: +200 KB (~24%)
This seems a bit much, and looking at the delta with sizoscope I'm not sure I understand what's causing this exactly 😅
Data
I can provide exact repro steps (right now stuff is just hacked together on a local branch).
But, here's all the sizoscope files, which I think should help already:
Additional context
@MichalStrehovsky mentioned on Discord he thinks (at least part of?) this might be caused by the object.GetType() goo that's pulled in by default because that's how object.ToString() works when no additional implementation is provided. This seems highly unfortunate, as eg. for libraries that's not a method you'd implement for usually most of your types (as you'd just never need to call that), and paying such a high cost in terms of binary size for that doesn't seem great 🥲
Would it make sense to consider adding some new option to explicitly disable that, and just get back the behavior that both .NET Native and NativeAOT in reflection disabled mode have when trying to call ToString(), ie. just printing EETypeRva:0x033EE048? That seems like an option that would certainly be useful in cases like this, especially for native library authors 🤔