Bug 26587 - AOT generic size explosion
Summary: AOT generic size explosion
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: master
Hardware: PC Mac OS
: High normal
Target Milestone: Untriaged
Assignee: Zoltan Varga
URL:
Depends on:
Blocks:
 
Reported: 2015-01-30 04:05 UTC by Rolf Bjarne Kvinge [MSFT]
Modified: 2015-04-13 19:23 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Rolf Bjarne Kvinge [MSFT] 2015-01-30 04:05:31 UTC
Test case: https://github.com/wotzisname/open-xml-sdk-xamarin (I used 529ce7014f50dd77f6d342af0450df5f40546700)

Change the architecture to ARMv7 and run on device. It will usually crash either at startup or when tapping the only button (might have to try a couple of times, once in a while it does actually work as well. Adding a couple of CWLs and rebuilding might make it easier to hit too).

The problem seems to be in the OpenXmlSdk.iOS.dll assembly, it's a 6.0MB assembly which turns into 357MB of native assembly and a 100MB object file. A quick look at the symbols seems to indicate many generic instantiations of different enum types:

> nm OpenXmlSdk.iOS.dll.armv7.o | grep EnumValue.*cctor|wc
     531    1593   59002
All those 531 types seems to be a generic type instantiated with different enum types.

> nm OpenXmlSdk.iOS.dll.armv7.o |grep System_Collections_Generic_KeyValuePair|wc
   19467   58401 3700340
This one has classes as well, but I couldn't find one struct instantiation which wasn't an enum.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2015-01-30 04:06:04 UTC
Zoltan, can you have a look?
Comment 3 Zoltan Varga 2015-01-30 04:45:46 UTC
We generate all generic instances we can find the source assembly if they are not instantiated with reference types, thats why there are so many instances here.
Comment 4 Zoltan Varga 2015-01-30 04:53:34 UTC
Generic value sharing is a fallback to avoid situations where no instance is found, we currently only avoid generating instances of the generic collection classes i.e. List/Dictionary because of it, we don't avoid generating instances of user classes.
Comment 5 Zoltan Varga 2015-02-01 16:09:51 UTC
Currently, there is no solution here other than modifying the source code.
Comment 6 Zoltan Varga 2015-04-07 00:37:32 UTC
Cycle6 will include support for sharing these instances.
Comment 7 Zoltan Varga 2015-04-07 23:35:24 UTC
With current master, the object file size is down to 71mb, but the compiled aot image still contains about 70k methods, so a lot of things are still not shared.
Comment 8 Zoltan Varga 2015-04-13 19:23:39 UTC
With mono master, the object file is down to 43mb, and the number of generic methods is down to 160.