Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
Using Xamarin.Android 188.8.131.52 (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.