xamarin 应用程序启动缓慢 [英] Slow startup of xamarin app

查看:27
本文介绍了xamarin 应用程序启动缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在 PCL 上开发跨平台应用,但目前我们仅使用 Android 设备进行测试.
我们担心的是,启动应用程序需要大约 6 到 8 秒(取决于我们测试的设备),这非常慢.
放置几个断点后,我们看到时间消耗相当均匀.
我们确实注意到这个特定部分花费的时间更长:

We are developing a cross platform app on a PCL, but for the time being we are only using android devices for testing.
Our concern is that its taking about 6 to 8 seconds (depending on which device we test it) to start the app, which is very slow.
After placing a few breakpoints we saw that the timing is consumed pretty evenly.
We did notice this particular parts took longer:

  • 在 MainActivity 上到达 onCreate() 之前 1 秒(有一个闪屏,在它之前只有一个图像和一个背景颜色)
  • 1s on base.OnCreate(bundle);
  • 1s on global::Xamarin.Forms.Forms.Init(this, bundle);
  • 1.5s on Page mainPage = new LogScreen();(创建主页然后将其设置为主导航页面).
  • 1s before reaching onCreate() on MainActivity (there's a splash screen before which only has one image and a background color)
  • 1s on base.OnCreate(bundle);
  • 1s on global::Xamarin.Forms.Forms.Init(this, bundle);
  • 1.5s on Page mainPage = new LogScreen(); (creating the main page to then set it as main navigation page).

推荐答案

我会将我们为此找到的所有解决方案放在一起,因此所有解决方案都集中在一个地方.

I'll put together all the solutions we found for this, so its all in one place.

链接的答案之一 这篇帖子,非常有用.

One of the answers linked this post, which was very useful.

除此之外,我们还做了以下几件事:

Besides that we also did the following things:

  • 在所有项目的属性上选中优化代码"框.不确定这是否会专门改善启动时间,但它似乎对总体性能有所帮助.
  • 添加AOT 和 LLVM.我们找到了一种方法来执行此操作,即使该选项在我们的 IDE 上不可用.这会显着增加构建时间,因此如果您想这样做,我建议您仅针对发布版本执行此操作.
  • 启用Xamarin 快速渲染.这是一个实验性的东西,所以你应该阅读一些关于它的文档,但它通过在 MainActivity 上添加这一行 global::Xamarin.Forms.Forms.SetFlags("FastRenderers_Experimental"); 来完成.OnCreate() 方法,在 global::Xamarin.Forms.Forms.Init(this, bundle);
  • 之前
  • 更新我们的 Xamarin.Forms Nuget 版本.这需要在您的解决方案的所有项目中使用相同的版本,我们在点击手势方面遇到了一些问题,这也因此得到了改进.
  • 链接 SDK 程序集.在链接"下的属性">Android 选项"上,您可以设置链接仅限 SDK 程序集".您也可以设置为所有程序集,但如果您使用自定义程序集,则不建议这样做.
  • 预加载屏幕.这大大提高了应用程序本身的性能,我们所做的是在每个屏幕上、背景上、下一个需要的视图和视图模型上加载,因此当将它们推送到导航堆栈时,它们已经加载了.这大大减少了页面之间的转换时间.
  • Check "optimize code" box on Properties in all projects. Not sure if that improves startup time specifically but it seems to help on the general performance a bit.
  • Add AOT and LLVM. We found a way to do this even though the option isn't available on our IDE. This increases the build time by a lot so if you want to do it I'd recommend doing it only for release builds.
  • Enable Xamarin Fast Renders. This is an experimental thing so you should read some documentation about it, but its done by adding this line global::Xamarin.Forms.Forms.SetFlags("FastRenderers_Experimental"); on MainActivity.OnCreate() method, before global::Xamarin.Forms.Forms.Init(this, bundle);
  • Update our Xamarin.Forms Nuget Version. This needs to be the same version on all projects of your solution, we had some issues with tap gestures which where also improved by this.
  • Link SDK Assemblies. On Properties > Android Options under Linking you can set to link "SDK Assemblies Only". You can also set to all assemblies, but this is not recommended if you are using custom assemblies.
  • Pre-Load screens. This improved by a lot the performance on the app itself what we did is load on each screen, on background, the views and view-models that where needed next, so when pushing them onto the navigation stack they were already loaded. This reduced by a lot the time on transition between pages.

这篇关于xamarin 应用程序启动缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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