I know that there's support for AOT in Xamarin for Android. After the software became free, all of its features became free as well. I read around the documentation and I enabled AOT by modifying my project.csproj file, as follows:
<AotAssemblies>True</AotAssemblies>
After making sure that my project path doesn't contain spaces (breaks process), I ran a build and I got an APK with both managed .NET DLLs and native compiled libs. Sadly, the app seems to be using the .NET DLLs and completely ignoring the native libs. Is there any way I can remedy this?
EDIT: Reading around some other Mono AOT-related questions, it appears that this might be how it is supposed to work. I wanted to AOT-compile my app in hopes to reduce the ~2 seconds start-up time, which did not change at all after I switched from JIT to AOT. Can somebody please explain this this to me?
BONUS: Is there any way I can enable advanced optimization flags? (e.g. -o)
AOT'ing your assemblies/code is not going to change the startup of the app's initialization (native app bootstrap + Xamarin/Mono initialization BUT not including any of your code execution time).
Now, if you are doing X amount of work that is CPU bound within your code, say within the OnCreate
(which you really should not be doing), you would (should) see a decrease in total time. I say should due to the fact that AOT'ing does not guarantee that you will see a faster execution time of a particular portion of code, it does eliminates the jitter, but there are lots of other factors involved. I've been using Mono (AOT w/ & w/o LLVM) for many years and you really need to instrument and test on your code.
Although the JIT mode is very fast, and the default optimizations in Mono have been tuned to provide a good balance between optimizations and JIT speed, AOT compilation provides a few extra benefits:
- Reduced startup time.
Note: This is particularly useful for large programs that might need to execute a lot of code before they are operational...
- Potential better performance.
Note: ....This means that certain programs might run slower as the generated code is more general than the specific code that the JIT can produce.
Ref: http://www.mono-project.com/docs/advanced/aot/
In terms of optimization of AOT code, enable LLVM along with AOT in your release builds for performance/instrumentation testing. Note: Testing is key, having a complete app test suite and internal instrumentation for collecting runtime performance is key to getting those 5 stars reviews on the app stores ;-)
EnableLLVM
A boolean property that determines whether or not LLVM will be used when Ahead-of-Time compiling assemblines into native code. Support for this property was added in Xamarin.Android 5.1.
This property is False by default.
This property is ignored unless the $(AotAssemblies) MSBuild property is True.
AotAssemblies
A boolean property that determines whether or not assemblies will be Ahead-of-Time compiled into native code and included in the .apk. Support for this property was added in Xamarin.Android 5.1.
This property is False by default.