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

查看:596
本文介绍了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);
  • global::Xamarin.Forms.Forms.Init(this, bundle);上的
  • 1s
  • 上的
  • 1.5s(创建主页,然后将其设置为主导航页).
  • 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.

其中一个答案链接 这个帖子,非常有用.

此外,我们还做了以下事情:

Besides that we also did the following things:

  • 在所有项目的属性"中选中"优化代码"框.不确定是否可以专门缩短启动时间,但似乎对整体性能有所帮助.
  • 添加 AOT和LLVM .即使该选项在我们的IDE中不可用,我们也找到了一种方法来执行此操作.这会大大增加构建时间,因此,如果您要这样做,我建议仅对发行版本进行构建.
  • 启用 Xamarin快速渲染.这是一个实验性的事情,因此您应该阅读一些文档,但是可以通过在global::Xamarin.Forms.Forms.Init(this, bundle);
  • 之前在MainActivity.OnCreate()方法上添加此行global::Xamarin.Forms.Forms.SetFlags("FastRenderers_Experimental");来完成.
  • 更新我们的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天全站免登陆