使用 xamarin 提高 android 应用程序的启动性能
Boost startup performance in android app using xamarin
如何在我的 android 使用 C# 编写的 Xamarin.Android 应用程序上缩短启动时间 performance/lower ] 方法。
因为我的设备不是最旧的(摩托罗拉 Moto G3),我想知道为什么一些大型商业 apps/games 如 Clash of Clans 和 Facebook 有这么少的 "blackscreen" 时间和我的 little-bit easy - 俗气 android 应用程序甚至不从本地存储加载数据(只是从硬编码值创建数据模型)需要很长时间才能显示介绍屏幕。
即使创建一个全新的应用程序并通过 adb 在我的 phone 上启动它,也会有一些延迟
提前致谢
我首先要您检查 Debug
配置与签名 Release
配置在“启动性能”方面的实际差异。
遗憾的是,Debug
配置有一些项目需要到位才能进行调试。这也称为 Shared Runtime
和 Shared Platform
。这是 ~10MB 用于首先复制 运行。
Copying these core components is only done once as it takes quite a bit of time, but allows any subsequent applications running in debug mode to utilize them. Finally, we copy the actual application, which is small and quick:
所以这可能是一个因素。但是,让我们在这里谈谈其他一些选择:
您也可以使用 Fast Assembly Deployment
,它只会将程序集直接安装在设备上一次,然后复制自上次部署以来修改过的文件。
注意:默认情况下,这两个设置通过以下 MSBuild 属性“启用”:<AndroidUseSharedRuntime>true</AndroidUseSharedRuntime>
和 <EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
接下来就可以使用AOT
(注:写这篇文章的时候还处于实验阶段):
The AOT Compilation option (on the Packaging Properties page) enables Ahead-of-Time (AOT) compilation of assemblies. When this option is enabled, Just In Time (JIT) startup overhead is minimized by precompiling assemblies before runtime. The resulting native code is included in the APK along with the uncompiled assemblies. This results in shorter application startup time, but at the expense of slightly larger APK sizes.
The AOT Compilation option requires an Enterprise license or higher. AOT compilation is available only when the project is configured for Release mode, and it is disabled by default. For more information about AOT Compilation, see AOT.
您终于可以启用 LLVM Optimization Compiler
(注意:在撰写本文时处于试验阶段):
When the AOT Compilation option is enabled (on the Packaging Properties page), you can choose to enable the LLVM Optimizing Compiler for converting AOT-compiled assemblies into native code. The LLVM compiler creates smaller and faster compiled code, but at the expense of slower build times. The LLVM compiler is disabled by default.
Note that the LLVM Optimizing Compiler option requires a Business license or higher and is available only when AOT Compilation is enabled.
同时使用 AOT
和 LLVM
时请牢记此注意事项:
NOTE: AOT is currently an experimental feature. It is not recommended for production use. AOT and LLVM was available in Xamarin.Android 5.1, but it is no longer available in later Xamarin.Android versions. For more information, please see the release notes.
其他可能相关的项目,但我不会根据您的“文件 -> 新项目”假设进行详细说明:
- 应用程序退出前做太多工作
OnCreate()
- 没有尽可能多地缩小
.apk
以获得快速加载时间
如何在我的 android 使用 C# 编写的 Xamarin.Android 应用程序上缩短启动时间 performance/lower ] 方法。
因为我的设备不是最旧的(摩托罗拉 Moto G3),我想知道为什么一些大型商业 apps/games 如 Clash of Clans 和 Facebook 有这么少的 "blackscreen" 时间和我的 little-bit easy - 俗气 android 应用程序甚至不从本地存储加载数据(只是从硬编码值创建数据模型)需要很长时间才能显示介绍屏幕。
即使创建一个全新的应用程序并通过 adb 在我的 phone 上启动它,也会有一些延迟 提前致谢
我首先要您检查 Debug
配置与签名 Release
配置在“启动性能”方面的实际差异。
遗憾的是,Debug
配置有一些项目需要到位才能进行调试。这也称为 Shared Runtime
和 Shared Platform
。这是 ~10MB 用于首先复制 运行。
Copying these core components is only done once as it takes quite a bit of time, but allows any subsequent applications running in debug mode to utilize them. Finally, we copy the actual application, which is small and quick:
所以这可能是一个因素。但是,让我们在这里谈谈其他一些选择:
您也可以使用 Fast Assembly Deployment
,它只会将程序集直接安装在设备上一次,然后复制自上次部署以来修改过的文件。
注意:默认情况下,这两个设置通过以下 MSBuild 属性“启用”:<AndroidUseSharedRuntime>true</AndroidUseSharedRuntime>
和 <EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
接下来就可以使用AOT
(注:写这篇文章的时候还处于实验阶段):
The AOT Compilation option (on the Packaging Properties page) enables Ahead-of-Time (AOT) compilation of assemblies. When this option is enabled, Just In Time (JIT) startup overhead is minimized by precompiling assemblies before runtime. The resulting native code is included in the APK along with the uncompiled assemblies. This results in shorter application startup time, but at the expense of slightly larger APK sizes.
The AOT Compilation option requires an Enterprise license or higher. AOT compilation is available only when the project is configured for Release mode, and it is disabled by default. For more information about AOT Compilation, see AOT.
您终于可以启用 LLVM Optimization Compiler
(注意:在撰写本文时处于试验阶段):
When the AOT Compilation option is enabled (on the Packaging Properties page), you can choose to enable the LLVM Optimizing Compiler for converting AOT-compiled assemblies into native code. The LLVM compiler creates smaller and faster compiled code, but at the expense of slower build times. The LLVM compiler is disabled by default.
Note that the LLVM Optimizing Compiler option requires a Business license or higher and is available only when AOT Compilation is enabled.
同时使用 AOT
和 LLVM
时请牢记此注意事项:
NOTE: AOT is currently an experimental feature. It is not recommended for production use. AOT and LLVM was available in Xamarin.Android 5.1, but it is no longer available in later Xamarin.Android versions. For more information, please see the release notes.
其他可能相关的项目,但我不会根据您的“文件 -> 新项目”假设进行详细说明:
- 应用程序退出前做太多工作
OnCreate()
- 没有尽可能多地缩小
.apk
以获得快速加载时间