Using Xamarin.Android 220.127.116.11 (and most probably any version below) the method Resource.UpdateIdValues for the main assembly is called a very large number of times.
It is called by number of classes and nested classes for every generated "Resource" class, for every assembly in the current package, because of their .cctor calling global::Android.Runtime.ResourceIdManager.UpdateIdValues().
In a large application, this method weights about 9500 lines of simple (mostly duplicate) assignations and on a quite fast CPU (i7-4790 @ 3.6GHz) virtual machine, the time spent running all these UpdateIdValues is about 280ms.
Lower powered CPUs, on actual devices, this time goes up significantly and impacts the startup time of the application.
@Eno: Could UpdateIdValues() have a check to skip re-running after it's been run once?
UpdateIdValues() is invoked only once per type, it is in the static constructor. There is no chance for re-running. And they are invoked because they are required.
We need reproducible case that this really matters.
Created attachment 14960 [details]
UpdateIdValues many calls repro
* Restore all the packages (all googleplay is included to make Resources.cs very large)
* Place a breakpoint somewhere in the UpdateIdValues method
* Notice that the method is called multiple times
This gets worse if there are libraries to be initialized, because all Resource.cs classes call global::Android.Runtime.ResourceIdManager.UpdateIdValues();
Thank you for the repro case. OK, you are right, there could be problematic cases that it could matter in reality.
As a principle, they are invoked because they are required, and they are invoked once, and the number of the calls are not going to be reduced.
But there could be chance that we can optimize the implementation of UpdateIdValues() like reducing required reflection calls for newer libraries (they are there because we need to keep compatibility with libraries that had been published earlier).
It is not likely short term task to slip in to the next major release, but I would seek for the chance in that direction.
Actually Jonp came up with another idea to quickly workaround this issue and now it is applied. So hopefully it is included in the next major release (unless it causes any drawback).
Thanks for the report.
Notice (2018-05-21): bugzilla.xamarin.com will be
switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.
Please join us on
Visual Studio Developer Community and
GitHub to continue tracking
issues. Bugzilla will remain available for reference in read-only mode.
We will continue to work on open Bugzilla bugs and copy them to the new
locations as needed for follow-up. The See Also field
on each Bugzilla bug will be updated with a link to its new location
After Bugzilla is read-only, if you have new information to add for a
bug that does not yet have a matching issue on Developer Community or
GitHub, you can create a follow-up issue in the new location. Copy and
paste the title and description from this bug, and then add your new
details. You can get a pre-formatted version of the title and
In special cases you might also want the comments:
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.