mozilla-mobile / fenix

⚠️ Fenix (Firefox for Android) moved to a new repository. It is now developed and maintained as part of: https://github.com/mozilla-mobile/firefox-android
https://github.com/mozilla-mobile/firefox-android
Mozilla Public License 2.0
6.47k stars 1.28k forks source link

Count the number of layout and measure passes on Startup #16374

Closed MarcLeclair closed 3 years ago

MarcLeclair commented 3 years ago

The number of layout and measure passes on startup can impact performance. We sometimes do multiple passes over our layouts during startup and we should definitely aim to reduce those.

Time: 3 days

┆Issue is synchronized with this Jira Task

mcomella commented 3 years ago

I looked into this and was able to add an OnGlobalLayoutListener. However, the number of layouts varies each time we start the app so it's somewhat impractical to add a check that the number of layouts does not increase. I can think of a few mediocre solutions (bolding the best ones):

Notably, each time a layout occurs, we have no information as to why that layout occurred so, presumably, the only way to get that is with better tooling or our own introspection code that looks "pre-layout" (e.g. inspects the view hierarchy on layout). These could help us figure out why the layout count varies so much and what to do about it. (maybe probe would help?)

As for what we should do, I would recommend we just start with wrapping layout inflation calls and optionally leave the code in that counts the number of layouts if we think it's useful for our own reference (we could also add a profiler call there too though I found relating the markers to the stack view in the profiler was less easy than I'd hope).

mcomella commented 3 years ago

@MarcLeclair Any thoughts on my proposal?

MarcLeclair commented 3 years ago

That's interesting. I wonder why the number varies. I think I have some thought considering the measure hook. We could override all our "layouts" with our own and instrument the onMeasure. However that sounds quite tedious and prone to breaking imo.

First: I'm not sure what you mean by the "Async UI". I thought all our UI was synchronous? Or did you mean callbacks that changes the views?

On another note, we could try a listener for whenever we have a new view added similar to this Hierarchy Change Listener

Another idea would be to have the Choreographer.frameCallBack on start up and see if we can just get the difference in view between point A and point B? Now sure if that's possible though.

Lastly, I think a mix of 1 and 3 might be our best bet but a bit more work

mcomella commented 3 years ago

That's interesting. I wonder why the number varies.

I assume it's due to the timing of the async data arriving: if multiple datasets arrive on the same frame, we can avoid some layouts.

First: I'm not sure what you mean by the "Async UI". I thought all our UI was synchronous? Or did you mean callbacks that changes the views?

I'm referring to us asynchronously fetching data from the DB (e.g. users' collections) and then populating the screen at later point rather than blocking the first frame on all of the data (i.e. to make it so there's only 1 frame total).

Another idea would be to have the Choreographer.frameCallBack on start up and see if we can just get the difference in view between point A and point B? Now sure if that's possible though.

I'm not sure how this would help – it'd be the same as counting the number of layouts (though it could help us determine why the layouts are happening – is that what you meant?).

Lastly, I think a mix of 1 and 3 might be our best bet but a bit more work

I'm not sure what 1-3 refers to. Is that the three items in my comment or something in your comment?

The most viable investigations, from Matrix and these comments, seem to be:

mcomella commented 3 years ago

OnHierarchyChange...

This only gets called for direct descendants so isn't helpful for counting or debugging.

mcomella commented 3 years ago

Using probe-like interceptor to figure out what is causing layout changes

I created a custom probe-like thing that set a LayoutInflater.Factory2 and instantiates views in onCreateView (only a subset because of incomplete implementation), giving us an opportunity to add listeners to those views. In particular, I added an OnLayoutChangeListener and, each time that listener is called, I post a runnable to the main thread to batch together all the views that are laid out together. This is a sample output, me adding new lines between batches:

2020-11-09 15:48:59.252 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: Layout count 1
2020-11-09 15:48:59.305 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: HomeActivity layout count #1 
2020-11-09 15:48:59.339 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.Barrier{88e26fa G.ED..... ......I. 859,0-859,0 #7f0a003d app:id/accessory_button_barrier}
2020-11-09 15:48:59.339 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View org.mozilla.fenix.components.toolbar.TabCounter{3c2f4ab VFE...CL. ......ID 859,14-985,140 #7f0a0468 app:id/tab_button}
2020-11-09 15:48:59.339 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.AppCompatImageView{7d07708 V.ED..... ......ID 0,0-95,126 #7f0a0259 app:id/icon}
2020-11-09 15:48:59.339 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.AppCompatImageView{374ea1 V.ED..... ......ID 0,0-95,126 #7f0a0348 app:id/notification_dot}
2020-11-09 15:48:59.339 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View mozilla.components.browser.menu.view.MenuButton{307b8c6 VFE...C.. ......ID 985,14-1080,140 #7f0a02cb app:id/menuButton}
2020-11-09 15:48:59.339 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{c62a8ec V.E...... ......ID 0,1581-1080,1731 #7f0a04ab app:id/toolbarLayout}
2020-11-09 15:48:59.339 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View com.google.android.material.appbar.CollapsingToolbarLayout{3ba3087 V.ED..... ......ID 0,0-1080,236}
2020-11-09 15:48:59.339 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View com.google.android.material.appbar.AppBarLayout{bb4253e V.E...... ......ID 0,0-1080,236 #7f0a024a app:id/homeAppBar}
2020-11-09 15:48:59.339 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.AppCompatImageButton{9f5674e VFED..C.. ......ID 891,43-954,106 #7f0a03ae app:id/remove_collection_placeholder}
2020-11-09 15:48:59.339 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{74af06f V.E...... ......ID 42,84-1038,399 #7f0a033e app:id/no_collections_wrapper}
2020-11-09 15:48:59.340 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.recyclerview.widget.RecyclerView{b00ef9f VFED..... ......ID 0,236-1080,1841 #7f0a0405 app:id/sessionControlRecyclerView}
2020-11-09 15:48:59.340 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.coordinatorlayout.widget.CoordinatorLayout{504617c V.E...... ......ID 0,0-1080,1731 #7f0a024d app:id/homeLayout}
2020-11-09 15:48:59.340 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.ContentFrameLayout{a797a05 V.E...... ......ID 0,0-1080,1731 #1020002 android:id/content}
2020-11-09 15:48:59.340 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.FitWindowsLinearLayout{dc4aa5a V.E...... ......ID 0,0-1080,1731 #7f0a004d app:id/action_bar_root}

2020-11-09 15:48:59.444 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: Layout count 2
2020-11-09 15:48:59.446 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: HomeActivity layout count #2
2020-11-09 15:48:59.451 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View org.mozilla.fenix.components.toolbar.TabCounter{3c2f4ab VFE...CL. ......ID 859,14-985,140 #7f0a0468 app:id/tab_button}
2020-11-09 15:48:59.451 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{c62a8ec V.E...... ......ID 0,1581-1080,1731 #7f0a04ab app:id/toolbarLayout}
2020-11-09 15:48:59.451 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.coordinatorlayout.widget.CoordinatorLayout{504617c V.E...... ......ID 0,0-1080,1731 #7f0a024d app:id/homeLayout}
2020-11-09 15:48:59.451 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.ContentFrameLayout{a797a05 V.E...... ......ID 0,0-1080,1731 #1020002 android:id/content}
2020-11-09 15:48:59.451 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.FitWindowsLinearLayout{dc4aa5a V.E...... ......ID 0,0-1080,1731 #7f0a004d app:id/action_bar_root}

2020-11-09 15:48:59.477 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: Layout count 3
2020-11-09 15:48:59.479 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: HomeActivity layout count #3
2020-11-09 15:48:59.528 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View org.mozilla.fenix.components.toolbar.TabCounter{3c2f4ab VFE...CL. ......ID 859,14-985,140 #7f0a0468 app:id/tab_button}
2020-11-09 15:48:59.528 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{c62a8ec V.E...... ......ID 0,1581-1080,1731 #7f0a04ab app:id/toolbarLayout}
2020-11-09 15:48:59.528 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.coordinatorlayout.widget.CoordinatorLayout{504617c V.E...... ......ID 0,0-1080,1731 #7f0a024d app:id/homeLayout}
2020-11-09 15:48:59.528 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.ContentFrameLayout{a797a05 V.E...... ......ID 0,0-1080,1731 #1020002 android:id/content}
2020-11-09 15:48:59.528 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.FitWindowsLinearLayout{dc4aa5a V.E...... ......ID 0,0-1080,1731 #7f0a004d app:id/action_bar_root}

2020-11-09 15:48:59.583 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: Layout count 4
2020-11-09 15:48:59.585 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: HomeActivity layout count #4
2020-11-09 15:48:59.595 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View org.mozilla.fenix.components.toolbar.TabCounter{3c2f4ab VFE...CL. ......ID 859,14-985,140 #7f0a0468 app:id/tab_button}
2020-11-09 15:48:59.595 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{c62a8ec V.E...... ......ID 0,1581-1080,1731 #7f0a04ab app:id/toolbarLayout}
2020-11-09 15:48:59.595 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.coordinatorlayout.widget.CoordinatorLayout{504617c V.E...... ......ID 0,0-1080,1731 #7f0a024d app:id/homeLayout}
2020-11-09 15:48:59.595 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.ContentFrameLayout{a797a05 V.E...... ......ID 0,0-1080,1731 #1020002 android:id/content}
2020-11-09 15:48:59.595 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.FitWindowsLinearLayout{dc4aa5a V.E...... ......ID 0,0-1080,1731 #7f0a004d app:id/action_bar_root}

2020-11-09 15:48:59.610 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: Layout count 5
2020-11-09 15:48:59.612 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: HomeActivity layout count #5
2020-11-09 15:48:59.617 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View org.mozilla.fenix.components.toolbar.TabCounter{3c2f4ab VFE...CL. ......ID 859,14-985,140 #7f0a0468 app:id/tab_button}
2020-11-09 15:48:59.617 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{c62a8ec V.E...... ......ID 0,1581-1080,1731 #7f0a04ab app:id/toolbarLayout}
2020-11-09 15:48:59.617 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.coordinatorlayout.widget.CoordinatorLayout{504617c V.E...... ......ID 0,0-1080,1731 #7f0a024d app:id/homeLayout}
2020-11-09 15:48:59.617 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.ContentFrameLayout{a797a05 V.E...... ......ID 0,0-1080,1731 #1020002 android:id/content}
2020-11-09 15:48:59.617 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.FitWindowsLinearLayout{dc4aa5a V.E...... ......ID 0,0-1080,1731 #7f0a004d app:id/action_bar_root}

2020-11-09 15:48:59.627 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: Layout count 6
2020-11-09 15:48:59.762 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: HomeActivity layout count #6
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View org.mozilla.fenix.components.toolbar.TabCounter{3c2f4ab VFE...CL. ......ID 859,14-985,140 #7f0a0468 app:id/tab_button}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{c62a8ec V.E...... ......ID 0,1581-1080,1731 #7f0a04ab app:id/toolbarLayout}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{e063e46 VFE...CL. ......ID 0,21-168,189 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{fc60807 VFE...CL. ......ID 168,21-336,189 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{a2dbd34 VFE...CL. ......ID 336,21-504,189 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{f57975d VFE...CL. ......ID 504,21-672,189 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{8d2b57e VFE...CL. ......ID 0,242-168,410 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{277dadf VFE...CL. ......ID 168,242-336,410 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{932532c VFE...CL. ......ID 336,242-504,410 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{fcd01f5 VFE...CL. ......ID 504,242-672,410 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{e063e46 VFE...CL. ......ID 0,21-249,189 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{fc60807 VFE...CL. ......ID 249,21-498,189 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{a2dbd34 VFE...CL. ......ID 498,21-747,189 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{f57975d VFE...CL. ......ID 747,21-996,189 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{8d2b57e VFE...CL. ......ID 0,242-249,410 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{277dadf VFE...CL. ......ID 249,242-498,410 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{932532c VFE...CL. ......ID 498,242-747,410 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{fcd01f5 VFE...CL. ......ID 747,242-996,410 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.recyclerview.widget.RecyclerView{960ab8a VFE...... ......ID 0,0-996,442 #7f0a04be app:id/top_sites_list}
2020-11-09 15:48:59.775 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.viewpager2.widget.ViewPager2{92945fb V.E...... ......ID 0,0-996,463 #7f0a04bf app:id/top_sites_pager}
2020-11-09 15:48:59.776 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View org.mozilla.fenix.home.sessioncontrol.viewholders.topsites.PagerIndicator{5077618 V.E...... ......ID 478,463-518,479 #7f0a035b app:id/page_indicator}
2020-11-09 15:48:59.776 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{74af06f V.E...... ......ID 42,584-1038,899 #7f0a033e app:id/no_collections_wrapper}
2020-11-09 15:48:59.776 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.recyclerview.widget.RecyclerView{b00ef9f VFED..... ......ID 0,236-1080,1841 #7f0a0405 app:id/sessionControlRecyclerView}
2020-11-09 15:48:59.776 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.coordinatorlayout.widget.CoordinatorLayout{504617c V.E...... ......ID 0,0-1080,1731 #7f0a024d app:id/homeLayout}
2020-11-09 15:48:59.776 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.ContentFrameLayout{a797a05 V.E...... ......ID 0,0-1080,1731 #1020002 android:id/content}
2020-11-09 15:48:59.776 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.FitWindowsLinearLayout{dc4aa5a V.E...... ......ID 0,0-1080,1731 #7f0a004d app:id/action_bar_root}

2020-11-09 15:48:59.798 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: Layout count 7
2020-11-09 15:48:59.800 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: HomeActivity layout count #7
2020-11-09 15:48:59.804 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View org.mozilla.fenix.components.toolbar.TabCounter{3c2f4ab VFE...CL. ......ID 859,14-985,140 #7f0a0468 app:id/tab_button}
2020-11-09 15:48:59.804 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{c62a8ec V.E...... ......ID 0,1581-1080,1731 #7f0a04ab app:id/toolbarLayout}
2020-11-09 15:48:59.804 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.coordinatorlayout.widget.CoordinatorLayout{504617c V.E...... ......ID 0,0-1080,1731 #7f0a024d app:id/homeLayout}
2020-11-09 15:48:59.804 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.ContentFrameLayout{a797a05 V.E...... ......ID 0,0-1080,1731 #1020002 android:id/content}
2020-11-09 15:48:59.804 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.FitWindowsLinearLayout{dc4aa5a V.E...... ......ID 0,0-1080,1731 #7f0a004d app:id/action_bar_root}

2020-11-09 15:48:59.833 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: Layout count 8
2020-11-09 15:48:59.841 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: HomeActivity layout count #8
2020-11-09 15:48:59.847 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{e063e46 VFE...CL. ......I. 0,21-249,189 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.847 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{a2dbd34 VFE...CL. ......I. 498,21-747,189 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.847 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{f57975d VFE...CL. ......I. 747,21-996,189 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.847 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{8d2b57e VFE...CL. ......I. 0,242-249,410 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.847 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{932532c VFE...CL. ......I. 498,242-747,410 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.847 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.recyclerview.widget.RecyclerView{960ab8a VFE...... ......ID 0,0-996,442 #7f0a04be app:id/top_sites_list}
2020-11-09 15:48:59.847 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.viewpager2.widget.ViewPager2{92945fb V.E...... ......ID 0,0-996,463 #7f0a04bf app:id/top_sites_pager}
2020-11-09 15:48:59.847 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.recyclerview.widget.RecyclerView{b00ef9f VFED..... ......ID 0,236-1080,1841 #7f0a0405 app:id/sessionControlRecyclerView}
2020-11-09 15:48:59.847 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.coordinatorlayout.widget.CoordinatorLayout{504617c V.E...... ......ID 0,0-1080,1731 #7f0a024d app:id/homeLayout}
2020-11-09 15:48:59.847 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.ContentFrameLayout{a797a05 V.E...... ......ID 0,0-1080,1731 #1020002 android:id/content}
2020-11-09 15:48:59.847 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.FitWindowsLinearLayout{dc4aa5a V.E...... ......ID 0,0-1080,1731 #7f0a004d app:id/action_bar_root}

2020-11-09 15:48:59.854 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: Layout count 9
2020-11-09 15:48:59.858 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: HomeActivity layout count #9
2020-11-09 15:48:59.861 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{277dadf VFE...CL. ......I. 249,242-498,410 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.861 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{fcd01f5 VFE...CL. ......I. 747,242-996,410 #7f0a04bc app:id/top_site_item}
2020-11-09 15:48:59.862 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.recyclerview.widget.RecyclerView{960ab8a VFE...... ......ID 0,0-996,442 #7f0a04be app:id/top_sites_list}
2020-11-09 15:48:59.862 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.viewpager2.widget.ViewPager2{92945fb V.E...... ......ID 0,0-996,463 #7f0a04bf app:id/top_sites_pager}
2020-11-09 15:48:59.862 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.recyclerview.widget.RecyclerView{b00ef9f VFED..... ......ID 0,236-1080,1841 #7f0a0405 app:id/sessionControlRecyclerView}
2020-11-09 15:48:59.862 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.coordinatorlayout.widget.CoordinatorLayout{504617c V.E...... ......ID 0,0-1080,1731 #7f0a024d app:id/homeLayout}
2020-11-09 15:48:59.862 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.ContentFrameLayout{a797a05 V.E...... ......ID 0,0-1080,1731 #1020002 android:id/content}
2020-11-09 15:48:59.862 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.FitWindowsLinearLayout{dc4aa5a V.E...... ......ID 0,0-1080,1731 #7f0a004d app:id/action_bar_root}

2020-11-09 15:48:59.881 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: Layout count 10
2020-11-09 15:48:59.882 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter: HomeActivity layout count #10
2020-11-09 15:48:59.885 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View org.mozilla.fenix.components.toolbar.TabCounter{3c2f4ab VFE...CL. ......ID 859,14-985,140 #7f0a0468 app:id/tab_button}
2020-11-09 15:48:59.885 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.constraintlayout.widget.ConstraintLayout{c62a8ec V.E...... ......ID 0,1581-1080,1731 #7f0a04ab app:id/toolbarLayout}
2020-11-09 15:48:59.885 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.coordinatorlayout.widget.CoordinatorLayout{504617c V.E...... ......ID 0,0-1080,1731 #7f0a024d app:id/homeLayout}
2020-11-09 15:48:59.885 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.ContentFrameLayout{a797a05 V.E...... ......ID 0,0-1080,1731 #1020002 android:id/content}
2020-11-09 15:48:59.885 14426-14426/org.mozilla.fenix.debug D/StartupLayoutCounter:     View androidx.appcompat.widget.FitWindowsLinearLayout{dc4aa5a V.E...... ......ID 0,0-1080,1731 #7f0a004d app:id/action_bar_root}
mcomella commented 3 years ago

It seems like this could be useful to understand what's being laid out in each pass and thus what might be causing the layouts to occur.

mcomella commented 3 years ago

"Layout count" comes from LayoutInflater.Factory2 while "HomeActivity layout count" comes from the global layout listener. Notably, sometimes the global layout listener increments more times (I've only seen once) than the Factory2 method – perhaps that's because my Factory2 method is missing some views.

mcomella commented 3 years ago

All of these contain android:id/content, which is the ContentFrameLayout that contains all of our content (i.e. its direct descendant to rootContainer. The listener is "Called when the layout bounds of a view changes due to layout processing." but I don't expect the layout bounds of that view to be changing – I wonder what this implies.

mcomella commented 3 years ago

Recap

The problem we're trying to solve is that layouts on start up are expensive so we don't want the number of layouts to increase.

Unfortunately, just asserting the number of layouts that happens on start up is impractical because it changes each run. It's unclear why the count varies, even when using a probe-like mechanism.

Proposal

Further investigating why the layout count varies and trying to fix it seems like a rabbit hole better fit for offense so I propose we:

@MarcLeclair What do you think of my proposal? Do you think we should tackle any optional items? If so, which one? fwiw, I've probably spent the full timebox period on this issue already though I haven't been feeling totally productive.

mcomella commented 3 years ago

We're not focusing on defense right now.

stale[bot] commented 3 years ago

See: https://github.com/mozilla-mobile/fenix/issues/17373 This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

mcomella commented 3 years ago

We agree: let's close.