溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)

發(fā)布時(shí)間:2020-05-20 23:55:36 來源:網(wǎng)絡(luò) 閱讀:923 作者:流光漏洞 欄目:移動(dòng)開發(fā)

   You know what this timer means? Every quarter second a user spends staring at a blank screen instead of interfacing with your app is a quarter second more. they're willing to close your app and give their attention to something else. misunderstanding all the complex things that happen during your app startup can lead to some serious performance problems.

   Now,see, Android is pretty smart when it comes to understanding human performance perception. As soon as the user launches your application,Android will immediately display a start window,which will stay around untill your application is fully loaded,initialized,and can draw its first frame.

--你知道這個(gè)計(jì)時(shí)器是什么意思嗎?【這個(gè)不知道怎么翻譯,大概意思就是說如果啟動(dòng)時(shí)的白屏界面時(shí)間過長】。他們會(huì)希望把你的app關(guān)了,然后去做別的事情。在app啟動(dòng)過程中的那些復(fù)雜錯(cuò)誤的操作會(huì)導(dǎo)致一些嚴(yán)重的性能問題。

  現(xiàn)在我們了解了,android其實(shí)是很聰明的,它能夠明白人類對性能的感知。一旦用戶點(diǎn)擊桌面圖標(biāo),android會(huì)立即展示啟動(dòng)窗口,這個(gè)窗口將持續(xù),直到你的應(yīng)用完全加載,初始化,繪制首幀。

  

 App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)


This behavior is most often seen when your app is booted for the first time,but it can easily happen other times as well,like when the activity is brought to the foreground,or after the user backs out of your app,or after some portion of your app has been purged by the system to save memory.Basically,any time the user moves from something else to your application, there's a chance you can see this type of behavior.

--這種情況在在app冷啟動(dòng)時(shí)候很常見,但是也很容易發(fā)生在其他時(shí)候,比如活動(dòng)被置于前臺(tái),或者用于退出你的app,或者你的app的某些部分被系統(tǒng)清楚用于節(jié)省內(nèi)存?;旧?,任何時(shí)候,用戶向你的應(yīng)用轉(zhuǎn)移一些東西(應(yīng)該是指調(diào)用你的app),你也有機(jī)會(huì)看到這種情況。****套用知乎:cold start:應(yīng)用第一次啟動(dòng)。   warm start:

   App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)


  The important point here is this.Letting the user spend too much time looking at the start window gives then ample opportunity to get bored and move on to other things.And taking too long in general could even cause the Application Not Responding dialog to pop 

up.Neither of these are very good for user retention.

--真正重要的點(diǎn)是這個(gè)。讓用戶花太長時(shí)間在啟動(dòng)界面,會(huì)讓他們感到很枯燥,然后轉(zhuǎn)去做別的事情。并且花太長的時(shí)間在這上面,甚至?xí)?dǎo)致應(yīng)用彈出無響應(yīng)彈窗(NAR)。這些對于挽留用戶都是沒有好處的。

  App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)


  So from the technical side,the whole process works something like this.when the user launches your app, the system does a bit of work to load your application information and create a unique process for your app.

--所以,從技術(shù)方面,全部的進(jìn)程工作情況,就如圖下圖。當(dāng)用戶啟動(dòng)你的app,系統(tǒng)會(huì)做一點(diǎn)小工作,加載你的應(yīng)用信息,給你的app創(chuàng)建一個(gè)獨(dú)立的進(jìn)程。

  App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)


From there,the system will display the strating window and basically hang out until the application is up and running.

--從那以后,系統(tǒng)會(huì)顯示啟動(dòng)界面并且會(huì)持續(xù)到應(yīng)用啟動(dòng)和運(yùn)行。

 App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)


Meanwhile,the application process will create the application object and launch the main thread.

--同時(shí),應(yīng)用進(jìn)程會(huì)創(chuàng)建應(yīng)用對象,啟動(dòng)主線程。

  App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)

 This is where your startup activity will be initalized,created,inflated,and finally drawn.

--主線程完成activity的初始化,創(chuàng)建,膨脹,繪制。

 App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)

it's only at this point,after the application has drawn its first frame,that the system process then goes and swaps out the start window for the application.

--在這點(diǎn)上,當(dāng)應(yīng)用繪制了首幀之后,系統(tǒng)進(jìn)程會(huì)把啟動(dòng)窗口替換成app的顯示窗口。

   App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)


 Now,to be clear,the majority of that entire process happens pretty cleanly.There's not really much chance that performance can go off the rails.However,there are three big areas where things could become problematic that you should keep an eye on.

--現(xiàn)在很清楚了,大多數(shù)的進(jìn)程產(chǎn)生的很干凈(大概這個(gè)意思吧)。性能出差錯(cuò)的可能性也很小。但是還是有三個(gè)大的方面會(huì)造成問題,需要你自己關(guān)注。

  App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)


 The first thing you should really take a look at is all the work that goes into creating your activity class.Most often,there's lots of heavy lifting that occurs during this process,but heaviest has to be the inflation of layouts and loading of resources that goes along with it.This is not a cheap process,and if your layouts are too complex or you've got some blocking logic in there,this can cause some really big problems.

--第一件你需要真正關(guān)注的事情就是,所有的工作都會(huì)先創(chuàng)建你的activity 類。最經(jīng)常的,大量繁重任務(wù)發(fā)生在這個(gè)進(jìn)程期間。但是最繁重的還是inflation布局和加載資源。這不是一個(gè)廉價(jià)的進(jìn)程,如果你的布局太復(fù)雜,或者是你在這里產(chǎn)生了一些閉鎖邏輯,那就會(huì)造成×××煩。

 App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)

On a similar note,make sure you take a look at application initialization.For really complex apps,the initialization of the app object often becomes a junk drawer for lots of global classes that might be used between activities.So there tends to be lots of work here that could be deferred to later times or perhaps loded in a lazy-load fashion.

--同樣的,確定你關(guān)注了應(yīng)用的初始化,對于復(fù)雜的app,app對象的初始化經(jīng)常會(huì)成為一個(gè)大量全局類的一個(gè)垃圾抽屜,可能會(huì)被用在活動(dòng)中(翻譯的越來越不行了)。所以這里會(huì)有很多工作可能會(huì)被推遲,或者是在lazy-load模式下加載。


 App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)

Now there's lots of applications out there which provide custom start windows.This is either done to help brand the application or to make a slow load look like a custom-branded application.Now if you're doing this to hide bad load times,obcviously,you should fix that first.But if you're doing it for branding,then you need to be aware that there's a right and a wrong way to set this up,so that it does'nt influence the user perception too negatively.

--現(xiàn)在,很多的應(yīng)用都會(huì)提供啟動(dòng)窗口?;蛘邘椭故緫?yīng)用品牌,或者降慢應(yīng)用加載。既然你做這個(gè)就是為了隱藏不好的加載時(shí)間,那么你就應(yīng)該修復(fù)他。但是如果你設(shè)置品牌,那你就應(yīng)該注意到設(shè)置這個(gè)的正確和錯(cuò)誤的方式。以便不會(huì)讓用戶感覺到太消極。



  App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)

But before you run off into the weeds and try to fix these types of common patterns,you need to sit down and figure out if you have a problem in the first place.Thankfully,Android has a few tools to help.

--在解決問題之前,如果你在第一個(gè)位置有問題,你需要坐下來,找出它。感謝android有這些工具來幫助我們。

 App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)


 Firstly is display time.For releases after KitKat,Logcat will include an output line which displays the amount of time between when the process was launched and the activity finally drawn to the screen.This can be helpful,because it gives you a general idea how long it 

takes to occur for your application.

--首先是顯示時(shí)間。在KitKat(Android 4.4)版本之后,日志將會(huì)包含輸出行,它將顯示在從程序啟動(dòng)到activity最后繪制在屏幕這段總的時(shí)間。這是很有幫助的,對于你的應(yīng)用啟動(dòng)的時(shí)間,他會(huì)給出一個(gè)大體的建議。

 App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)

oh,by the way,not if you want to see this value inisde of Android Studio,you need to turn off filters for the Logcat output. So keep that in mind.

--噢,記住,如果你不想在Android Studio看到這些值,你需要在日志輸出上關(guān)掉過濾功能。

 App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)

 

  Secondly is reportFullyDrawn function.The displayed metric that's repoted in Logcat is useful for most situations where you'd like to track down the time it takes to go from application start to first viseble.Howere,in modern application development,there's often a great deal of lazy loading-that is,rather than blocking the initial drawing of the window,asynchronously loading resources and views in the background and updating the view hierachy accordingly.The result is that while the initial activity may be visible,it may not yet be fully loaded with respect to resources,which could be considered a separate metric to use when evaluating launch time performance.

--其次是reportFullyDrawn方法:我們通常來說會(huì)使用異步懶加載的方式來提升程序畫面的顯示速度,這通常會(huì)導(dǎo)致的一個(gè)問題是,程序畫面已經(jīng)顯示,可是內(nèi)容卻還在加載中。為了衡量這些異步加載資源所耗費(fèi)的時(shí)間,我們可以在異步加載完畢之后調(diào)用activity.reportFullyDrawn()方法來告訴系統(tǒng)此時(shí)的狀態(tài),以便獲取整個(gè)加載的耗時(shí)。

 App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)

  To address this concern,you can manually call the activity.reportFullyDrawn function to let the system know that your activity is finished with its lazy loading.

 App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)


 Third is method tracing.While display time and reportFullyDrawn give a good understanding of the overall load time of your application,they do not provide details into what may be causing particular parts of that pipeline to go longer than expected.To gain more insight in this area,you can use the start method tracing tool inside of Android Studio.

然后是Method Tracing:前面兩個(gè)方法提供了啟動(dòng)耗時(shí)的總時(shí)間,可是卻無法提供具體的耗時(shí)細(xì)節(jié)。為了獲取具體的耗時(shí)分布情況,我們可以使用Method Tracing工具來進(jìn)行詳細(xì)的測量。

 App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)

 

 And finally is the big one,Systrace.when you add trace functions inside of your onCreate methods,it will augment your logging,such that the Systrace tool can properly discover all the subsections and display them in this graphing process.

--最后的重頭戲是Systrace。最后是Systrace:我們可以在onCreate方法里面添加trace方法來聲明需要跟蹤的起止位置,系統(tǒng)會(huì)幫忙統(tǒng)計(jì)中間經(jīng)歷過的函數(shù)調(diào)用耗時(shí),并輸出報(bào)表。

 App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)


 

 

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI