fenix icon indicating copy to clipboard operation
fenix copied to clipboard

SearchFragment is noticibly slow on first run

Open severinrudie opened this issue 7 years ago • 25 comments

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

severinrudie avatar Oct 25 '19 16:10 severinrudie

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.

emalysz avatar Nov 25 '19 22:11 emalysz

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?

hkaancaliskan avatar Nov 28 '19 16:11 hkaancaliskan

@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.

severinrudie avatar Dec 03 '19 01:12 severinrudie

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.

severinrudie avatar Dec 17 '19 19:12 severinrudie

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 ¯_(ツ)_/¯.

hkaancaliskan avatar Dec 17 '19 20:12 hkaancaliskan

( 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

Malclir avatar Dec 17 '19 21:12 Malclir

Wow, good catch @MarcLeclair. It looks like you're already involved in discussion on that one in another issue, linking here for future readers.

[Bug] Long delay when loading new tab

severinrudie avatar Dec 18 '19 17:12 severinrudie

This is likely fixed by the same PR @hawkinsw posted for #7143. Will can close this also if it's fixed.

colintheshots avatar Dec 23 '19 20:12 colintheshots

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.

hkaancaliskan avatar Dec 23 '19 20:12 hkaancaliskan

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.

severinrudie avatar Dec 23 '19 22:12 severinrudie

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 😄

Malclir avatar Dec 23 '19 22:12 Malclir

At first I didn't see how #7143 is related to this. However, I think that I see it now:

  1. Click the Awesome Bar
  2. See the Awesome Bar UI appear (no delay here)
  3. Enter search term(s)
  4. Click Enter
  5. 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 :-)

hawkinsw avatar Dec 23 '19 23:12 hawkinsw

Added @Baron-Severin as an assignee because github doesn't have an needinfo flag!

Bugzilla FTW!

hawkinsw avatar Dec 23 '19 23:12 hawkinsw

@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.

severinrudie avatar Dec 24 '19 00:12 severinrudie

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:

  1. 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)

  2. 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 😛 )

Malclir avatar Dec 24 '19 05:12 Malclir

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?)

Malclir avatar Dec 24 '19 06:12 Malclir

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.

severinrudie avatar Dec 26 '19 18:12 severinrudie

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!

hawkinsw avatar Dec 26 '19 20:12 hawkinsw

Putting @MarcLeclair as an assignee because, again, github does not have a needinfo flag.

hawkinsw avatar Dec 26 '19 20:12 hawkinsw

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.

hawkinsw avatar Jan 10 '20 23:01 hawkinsw