[Bug] Performance: URL bar autocomplete is extremely unresponsive after Settings page was accessed (two seconds per keypress on Moto G5)
Steps to reproduce
Profile: https://perfht.ml/3bV8FNx
[Edit: adjusting STR to include the aspect about the Settings pane]
- Start up Fenix. Tap the plus button to open a new tab.
- Enter the word "goo", one letter at a time.
- Observe that the letters and the corresponding autocomplete results show up quickly.
- Go back to the Fenix start screen using the OS back button.
- Open the Kebab menu and go to Settings.
- Go back again, using the OS back button (you might need to tap it twice).
- Tap the plus button to open a new tab.
- Repeat step 2.
Expected behavior
Letters should appear quickly, editing should feel responsive.
Actual behavior
Everything is extremely sluggish. The UI hangs for multiple seconds per letter.
Device information
- Android device: Moto G5
- Fenix version: Nightly 200405 18:01, AS 0.55.0
Further information
Looking at the profile, the delay seems to be caused by creating autocomplete elements below the visible part of the list. And, scrolling down in the results for "g" or "go", I can see pages upon pages of results.
It would be good to find a way to render autocomplete results in a way that doesn't slow down everything so much. All rows have the same height, so if there's some kind of "virtual list" or "data grid" container component that can be used here, using it might speed things up quite a bit. At the moment, the Java call stacks show android.view.View.initialAwakenScrollBars being called many times per keypress, as individual views are added to the list.
As a short term workaround, the number of results could be limited more aggressively.
┆Issue is synchronized with this Jira Task
@mstange How long is the autocomplete list in this case? Is it 10? 100? etc.
Triage: we want to understand if this is representative of users, or e.g. a profile designed to be overwhelming for devices.
I see 62 results when I type "g". That's: 3 suggested search terms, 19 web sites which I frequently visit on Desktop (or maybe even have open in tabs on Desktop), 20 open Fenix tabs, and 20 regular matches from my history. I see 57 results when I add the o to make it "go": 3 + 18 + 16 + 20. And 55 for "goo": 1 + 18 + 16 + 20
Here's a screen recording: https://drive.google.com/open?id=1gPrBZ-dWIf7kmmmhMLVQcE4Q1i6Y94nD
@mstange Approximately many history items are in your profile?
Interesting: Right after I start up Fenix, URL bar interactions are much smoother. But once I open the settings page, everything slows down!
Before opening settings: https://perfht.ml/2VkGLnq After opening settings: https://perfht.ml/2VhZtfn Screen recording: https://drive.google.com/open?id=1e9WQPFxXOrUs-H6nZfP5Y_fFRZxuYJcS
@mstange Approximately many history items are in your profile?
How do I find out?
I haven't been able to reproduce yet (probably because I haven't synced data and I'm on a Pixel 2) but I took an AS profile and when clicking letters on the soft keyboard I see a ridiculous amount of churn. This screenshot is what happens after I press "o" (after pressing "g") before:

We have 4 traversals/layout passes. However, the three search suggestion views should be reused with different TextView content and no other views are introduced because I have no additional history. I'd potentially expect no layout passes! It's possible the G5 is being burdened with ridiculously long layout passes.
As an optimization, we could potentially avoid additional full layout passes by pre-filling all the views in the RecyclerView (e.g. 20 views pre-inserted and you can have at most 20 results). Then, we just change the text and the icon if there are results, hiding them if not. It seems like RecyclerView should be able to do this optimization for us (since it re-uses views) if the views are a fixed size but maybe it's not. Or maybe there is something else inefficient in the code. It could be useful to make a standalone app that mimics this behavior and take a profiler to see how it's different.
I created a standalone app (source) that mimics what we're doing in Fenix: each time a button is pressed, it modifies the content of items in a RecyclerView without growing the RecyclerView. Each time the button is pressed, we only see one layout:

The first block is dispatchTouchEvent while the many long tail events are the Recyclerview animation.
This confirms that we're doing something funky in Fenix each time we update the view.
Curiously addView is called despite the views not changing: I guess the RecyclerView removes and re-adds the views.
One additional optimization we can look into is called setFixedSize. From the docs:
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
setHasFixedSize(true)
MarcLeclair is working in this area so I'll unassign and let him continue the investigation.
Note: https://github.com/mozilla-mobile/fenix/issues/9406 is a general case version of this issue that may have a similar cause.
I haven't been able to reproduce yet (probably because I haven't synced data and I'm on a Pixel 2) but I took an AS profile and when clicking letters on the soft keyboard I see a ridiculous amount of churn.
Can you reproduce a performance difference before and after you go to Settings? For me the difference was quite stark even in a debug build without any history.
I tried reproducing on a G5 and wasn't able to, maybe it doesn't happen all the time. I'll keep an eye on it in case I can reproduce it
Based on @MarcLeclair comment above. Would need @ecsmyth to provide guidance on how important is this to keep pushing on if we can't reproduce it.
I can't reproduce on a Samsung Galaxy S10 or ZTE Maven using the str that include opening settings and force stopping between attempts. I've tried with and without sync enabled (dozens of bookmarks and history) on the Maven. For me the time to open the search UI after tapping on the url bar is faster the second time (i.e. after visiting settings), the suggestions for the first letter also seem faster for second search, and in both cases, there is a similar delay between letters after the first and the suggestions updating.
Lets discuss at triage, but my inclination is to put it back in the backlog and possibly take another crack in Q3 at developing consistent str.
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.