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.