Bug 18068 - locals init is forced to true, even when it is not set
Summary: locals init is forced to true, even when it is not set
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-02-28 04:56 UTC by Virgile Bello
Modified: 2014-03-03 21:25 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 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.

Related Links:
Status:
RESOLVED FIXED

Description Virgile Bello 2014-02-28 04:56:04 UTC
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
	 * (#497220).
	 */
	init_locals = TRUE;

Related issue:
https://bugzilla.novell.com/show_bug.cgi?id=497220

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.
Comment 1 Zoltan Varga 2014-03-02 17:07:25 UTC
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
Comment 2 Virgile Bello 2014-03-02 21:03:33 UTC
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?

Thanks.
Comment 3 Zoltan Varga 2014-03-03 12:28:43 UTC
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.
Comment 4 Virgile Bello 2014-03-03 20:47:08 UTC
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?
Comment 5 Zoltan Varga 2014-03-03 20:49:43 UTC
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.
Comment 6 Zoltan Varga 2014-03-03 20:52:18 UTC
Please report a bug against Xamarin.Android to add support for passing the mono runtime's -O=<opts> flag in that case.
Comment 7 Virgile Bello 2014-03-03 21:25:30 UTC
Ok thanks, I'll close that one then!