Open Bug 1807337 Opened 3 years ago Updated 10 months ago

Taking a screenshot on the main thread delays tabs tray from opening for ~178ms

Categories

(Firefox for Android :: Performance, defect)

All
Android
defect

Tracking

()

Performance Impact low

People

(Reporter: cpeterson, Unassigned)

Details

From github: https://github.com/mozilla-mobile/fenix/issues/21526.

Steps to reproduce

  • Open a web page
  • Click tabs tray

Expected behavior

No delay from taking screenshots.

Actual behavior

We see runUiThreadCallback on the main thread for 178ms (the exact time seems to vary – I've seen times as low as 120ms and higher than 178): https://share.firefox.dev/3m6UT10 In the native AndroidUI thread, we see PUiCompositorController::Msg_ScreenPixels. This was indicative of taking a screenshot. I commented out this line that takes a screenshot and the problem went away: https://share.firefox.dev/3zSFA12

It's unclear how often this is called: it may be cached and only called once per each tab (though that could still be pretty bad) and this may affect prioritization.

Device information

  • Android device: Moto G5
  • Fenix version: main 8a15e8a6818554eb9c7d66f00e2058ecfcee6eed Sep 27

It's possible this call occurs after the tabs tray is drawn and is of little consequence to users. I confirmed this is not the case: I did this by by sleeping in an onPreDraw listener and manually verifying the screen contents. Here's my patch:

diff --git a/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFragment.kt b/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFragment.kt
index 509149b6e..0fa4202a5 100644
--- a/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFragment.kt
+++ b/app/src/main/java/org/mozilla/fenix/tabstray/TabsTrayFragment.kt
@@ -13,6 +13,7 @@ import android.view.View
 import android.view.ViewGroup
 import androidx.annotation.VisibleForTesting
 import androidx.appcompat.app.AppCompatDialogFragment
+import androidx.core.view.doOnPreDraw
 import androidx.core.view.isVisible
 import androidx.fragment.app.activityViewModels
 import androidx.fragment.app.setFragmentResultListener
@@ -112,6 +113,13 @@ class TabsTrayFragment : AppCompatDialogFragment() {
             true
         )
 
+        tabsTrayBinding.tabWrapper.doOnPreDraw {
+            it.doOnPreDraw {
+                Thread.sleep(3000)
+                requireComponents.core.engine.profiler?.addMarker("onPreDraw", "tabsTrayBinding.tabWrapper")
+            }
+        }
+
         val args by navArgs<TabsTrayFragmentArgs>()
         val initialMode = if (args.enterMultiselect) {
             TabsTrayState.Mode.Select(emptySet())

When I ran this, I saw the screen freeze on the web page with the tabs tray counter highlighted with a click event (i.e. the tabs tray did not start drawing). Here's the profile that shows the runUiThreadCallback screenshot takes place before the sleep: https://share.firefox.dev/2Y45Zfi Note this is a debug build profile and the timing shouldn't be taken into account.

┆Issue is synchronized with this Jira Task

Change performed by the Move to Bugzilla add-on.

The severity field is not set for this bug.
:cpeterson, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(cpeterson)
Flags: needinfo?(cpeterson)

The Performance Impact Calculator has determined this bug's performance impact to be low. If you'd like to request re-triage, you can reset the Performance Impact flag to "?" or needinfo the triage sheriff.

Platforms: Android
Impact on browser: Causes noticeable jank
Websites affected: Rare

Performance Impact: --- → low
Severity: -- → S3
You need to log in before you can comment on or make changes to this bug.