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
GitHub or Developer Community 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.
It seems that locals init = false is ignored in Mono.
In method-to-ir.c, init_locals is ignored.
First, we have:
init_locals = header->init_locals;
then, a few lines after:
* Methods without init_locals set could cause asserts in various passes
init_locals = TRUE;
However, we would like to disable it in various performance critical loops. VTune analysis showed us that this forced initialization could take quite some time.
In our game engine, we often make use of unsafe and/or out parameters and would like this initialization to be really skipped when we turn it off. Very useful for all mathematics libraries and rendering loops.
We measured a performance improvement on Windows and expect it to be even bigger on ARM platform (Xamarin Android/Touch).
It would be great if this init_locals was not enforced to true.
Should be fixed in mono master cf2aa3162e6f2cfd3ba8d9aa60b5a531a8042c5d. Note that allowing this has a change to break a lot of programs, so its only enabled when the 'unsage' optimization flag is set, i.e.
mono -O=unsafe app.exe
Great, thanks for the fast fix!
However, our main concern for this was on iOS/Android.
Will there be anyway to enable it on those platform for dev & appstore packages somehow?
For ios, you can pass --aot-options=unsafe to 'mtouch' to enable this optimization, altough its better to just enable LLVM, which does agressive optimizations which probably get rid of most of the extra initialization instructions added by locals init.
For android, I don't know how to enable this, the mono JIT doesn't generate very good fp code so I doubt this will have too much effect.
On iOS we already use LLVM so you're right, it might not have a significant impact.
However on Android it probably would save lot of time (we measured it would actually save lot of time on Windows, which has a good JIT). Since we're making games, we have strong runtime requirements and if we could easily save 5~10% thanks to this simple change, that's something we're willing to take!
Would it be possible to add this startup flag to Xamarin.Android somehow? (maybe I should file a different bug for this?).
By the way, is there any ETA/plan for LLVM on Xamarin.Android?
LLVM for android is not planned in the near future since it would only work with ahead-of-time compilation which is not supported on xamarin.android right now.
Please report a bug against Xamarin.Android to add support for passing the mono runtime's -O=<opts> flag in that case.
Ok thanks, I'll close that one then!