在Xamarin for Android(Visual Studio)中启用AOT [英] Enable AOT in Xamarin for Android (Visual Studio)

查看:330
本文介绍了在Xamarin for Android(Visual Studio)中启用AOT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Xamarin for Android中支持AOT.该软件免费后,其所有功能也免费.我阅读了文档,并通过修改 project.csproj 文件来启用AOT,如下所示:

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>

确保我的项目路径中不包含空格(中断过程)后,我运行了构建,并获得了一个由两者托管的.NET DLL 组成的APK.本机编译的库.可悲的是,该应用程序似乎正在使用.NET DLL,而完全忽略了本机库.我有什么办法可以解决这个问题?

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?

阅读其他一些与Mono AOT相关的问题,看来这可能是它应该如何工作的.我想对我的应用程序进行AOT编译,以希望减少〜2秒的启动时间,在我从JIT切换到AOT之后,它根本没有改变.有人可以向我解释一下吗?

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?

奖励:有什么方法可以启用高级优化标志? (例如-o)

BONUS: Is there any way I can enable advanced optimization flags? (e.g. -o)

推荐答案

自动执行程序集/代码不会改变应用程序初始化的启动(本地应用程序引导+ Xamarin/Mono初始化但不包括您的任何代码执行时间).

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).

现在,如果您正在执行代码中CPU绑定的 X 大量工作,请在OnCreate中说(您实际上应该要做) ,您应该(应该)看到总时间减少了.我说应该是因为AOT'ing不能保证您会看到特定代码部分的执行时间更快,但确实可以消除抖动,但是还涉及许多其他因素.我已经使用Mono(AOT w/o w/o LLVM)多年了,您确实需要对您的代码进行检测和测试.

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.

尽管JIT模式非常快,并且Mono中的默认优化已经过调整,可以在优化和JIT速度之间取得良好的平衡,但是AOT编译提供了一些额外的好处:

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:

  • 减少了启动时间.

注意:这对于大型程序可能特别有用,大型程序可能需要先执行很多代码,然后才能运行 ...

Note: This is particularly useful for large programs that might need to execute a lot of code before they are operational...

  • 可能会有更好的表现.
  • Potential better performance.

注意:....这意味着某些程序的运行速度可能会变慢,因为生成的代码比JIT可以生成的特定代码更通用.

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.

参考: http://www.mono-project.com/docs/advanced /aot/

就AOT代码的优化而言,请在您的发行版本中将LLVM与AOT一起启用,以进行性能/仪器测试.注意:测试是关键,拥有完整的应用程序测试套件和用于收集运行时性能的内部工具对于在应用程序商店上获得这5星评价至关重要;-)

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

EnableLLVM

一个布尔属性,用于确定在将提前编译为本机代码时是否使用LLVM. Xamarin.Android 5.1中添加了对此属性的支持.

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.

此属性默认为False.

This property is False by default.

除非$(AotAssemblies)MSBuild属性为True,否则将忽略此属性.

This property is ignored unless the $(AotAssemblies) MSBuild property is True.


AotAssemblies

AotAssemblies

一个布尔属性,用于确定是否将程序集提前编译为本机代码并包含在.apk中. Xamarin.Android 5.1中添加了对此属性的支持.

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.

此属性默认为False.

This property is False by default.

这篇关于在Xamarin for Android(Visual Studio)中启用AOT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆