SearchFragment is noticibly slow on first run
Steps to reproduce
- Open a fresh Fenix instance
- Click on the URL bar
Expected behavior
- Search fragment should appear quickly
Actual behavior
- Search fragment is noticeably slow to appear
- This only happens the first time the SearchFragment is launched
Device information
- Android device: physical Pixel 2, emulator
- Fenix version: 9d91108f4e6576860bc1da734768b4422d08cba8 (current head of master)
Notes
I didn't spend much time on this, but on my emulator the first launch (from URL bar click to onViewCreated) took about 160 MS. Follow up launches varied, but hovered around 30-60 MS. I believe the animated transition makes these numbers look worse than they are (follow up launches feel quite snappy).
┆Issue is synchronized with this Jira Task
After capturing this in the profiler, SearchFragment's onCreateView() indeed takes longer after first run. First run: 1,048,032 μs. Second run: 322,882 μs. Breaking this down, it looks like the increase is mostly due to the time spend in init for both ToolbarView and AwesomeBarView.
This problem looks like fixed for me after Nightly 191128 11:47 (Build #13321153) 📦: 24.0.0, 3183401f0 🦎: 72.0a1-20191126093448 XZ1, Android 10 Can someone confirm? Or initializing megazord asynchronously meet the required time of searchfragment?
@boek and I were still able to reproduce this, although it's less noticeable on newer devices. We did some investigation and it looks like there's also a very substantial amount of time spent in the SearchFragment consumeBy(searchStore) block. This might be easier for us to fix since view init is handled in AC. Once we have a better idea of what's going on, we can open an AC issue as well.
It may be possible to fix the perceived perf issue here without modifying toolbar internals by inflating the toolbar on a background thread on app init.
It may be possible to fix the perceived perf issue here without modifying toolbar internals by inflating the toolbar on a background thread on app init.
Androidx page of async layout inflater. Just wanted to help ¯_(ツ)_/¯.
( I just saw this issue), and I came across a similar problem where the initialization of the ToolBar took ~500ms-1 second (it was varying a lot) when creating a new tab and navigating to a website. I was wondering if using AsyncLayoutInflate could be used there too? (I'll add my trace for reference -- check from timestamp 27 second until 32 second, thats when I entered the URL search bar until the webpage fully loaded) new_tab.trace.zip
Wow, good catch @MarcLeclair. It looks like you're already involved in discussion on that one in another issue, linking here for future readers.
This is likely fixed by the same PR @hawkinsw posted for #7143. Will can close this also if it's fixed.
This is likely fixed by the same PR @hawkinsw posted for #7143. Will can close this also if it's fixed.
What about @Baron-Severin's offer about AsyncLayoutInflater? There will be a good perf gain.
I'd like to remeasure with @hawkinsw's fix, first. Async inflation is definitely a viable approach here, but it will add some complexity to code that's already fairly difficult to work with. If we see substantially better performance with this much simpler solution, I'd be happy to stick with that.
Also, @Baron-Severin I noticed that using AsyncLayoutInflater may cause trouble in some part of our code since we rely heavily on inflation of one part to create another. For instance, I tried it out with our DefaultBrowserToolbar and the inflation is somewhat sequential to inflate another (especially since we use a ViewStub then create one after the other). I'm not too sure how that would work out in some part of our code. Just food for thought I guess 😄
At first I didn't see how #7143 is related to this. However, I think that I see it now:
- Click the Awesome Bar
- See the Awesome Bar UI appear (no delay here)
- Enter search term(s)
- Click Enter
- See the Search Fragment Appear (delay here)
Please confirm that this is the use case.
If that is the correct user scenario then (based on the great trace from @MarcLeclair ) these are identical issues.
Would you be willing to confirm, @Baron-Severin? Thanks :-)
Added @Baron-Severin as an assignee because github doesn't have an needinfo flag!
Bugzilla FTW!
@hawkinsw nope, this issue is about a delay on step 2. I checked out your branch and it's still reproducible there, so it looks like you're right that it's unrelated.
AFAICT, the only options here are 1) async inflation, or 2) a deep dive into the AC toolbar implementation. Unless you see a better option @colintheshots.
So , I gave it a little test run (I've never really used asyncLayoutInflater so my implementation might be somewhat off -- especially since I'm not sure what everything does). But, the "preliminary" results seem promising (refer to here: issue 6274 in my fork)
TLDR: Without async layout inflate the searchFragment took ~574 ms With the async layout inflate the searchFragment took ~276 ms.
It is much faster but some of the UI behaves weirdly (like the hint for the url bar, and I didn't try when on a web page, I just did it to see early speed).
Traces for the interested: with and without async traces.zip
Timeline of each trace:
-
with_asyncInflater.trace :
-
Touch event happens at ~8.6 seconds
-
fragment appears at ~9.5 seconds ( you can see the asyncInflate takes ~3.56ms for the toolbar)
-
-
without_async.trace :
-
Touch event happens at ~10.4 seconds
-
fragment appears 11.5 seconds
-
If anyone could double check to verify I'm not crazy (@hawkinsw or maybe @Baron-Severin 😛 )
To answer my earlier comment for future reference: the Async loading seemed to affect the bitmap loading as well, so bitmaps should tried to be precomputed or something before calling our async (just did a push that did something like that, i guess?)
That's good progress! I haven't had time to really dive into this yet, but I was hoping we might be able to eagerly inflate the SearchFragment on a background thread during application init. Then on search bar click we block until the fragment is ready. Hopefully we would be able to get rid of the delay completely for the large majority of cases. I haven't looked into how feasible this is yet, though.
Hey @MarcLeclair - I tested this and also see a performance improvement. I left a few comments on your branch. They are mostly things that I am confused/intrigued about. Thanks for doing this great work!
Putting @MarcLeclair as an assignee because, again, github does not have a needinfo flag.
I think that I profiled this previously and I think it is related to Gecko session initialization. I will take another look later tonight and start to do more thorough investigation.