geckoview.js runs some global initializers repeatedly instead of once
Categories
(GeckoView :: General, defect, P3)
Tracking
(Not tracked)
People
(Reporter: robwu, Unassigned)
References
Details
(Keywords: good-first-bug)
geckoview.js has logic that is an inaccurate mirror of desktop's BrowserGlue.jsm + browser.js.
The most significant issue is that it runs some logic multiple times when they should be run once. Below I've listed relevant calls and their order of desktop vs mobile, and a summary of the differences and impact.
Desktop browser:
browser.js
'sonLoad
notifies"browser-window-before-show"
observers, which triggersSessionStore.jsm
'sonBeforeBrowserWindowShown
onBeforeBrowserWindowShown
awaits the first"browser-delayed-startup-finished"
, restores windows and ultimately triggers"sessionstore-windows-restored"
(once)."sessionstore-windows-restored"
runs once globally and is handled byBrowserGlue
's_onWindowsRestored
, which:- Calls
_scheduleStartupIdleTasks
, which schedules (many) idle tasks, mostly without deadlines (the last of which is triggeringremote-startup-requested
andmarionette-startup-requested
). - And schedules an idle timer with a 20 sec deadline to call
_scheduleBestEffortUserIdleTasks
, which schedules some idle tasks (including initialization of RemoteSettings and RemoteSecuritySettings).
- Calls
browser.js
'sonLoad
registers aMozAfterPaint
listener that calls_delayedStartup
._delayedStartup
runs per-window initialization methods._delayedStartup
chains a callback to theSessionStore.promiseAllWindowsRestored
(a global promise that resolves right aftersessionstore-windows-restored
) and then schedules per-window idle tasks (mostly without deadlines) in_schedulePerWindowIdleTask
_schedulePerWindowIdleTask
's last task is triggeringbrowser-idle-startup-tasks-finished
.
_delayedStartup
ultimately triggersbrowser-delayed-startup-finished
(without waiting for the above to complete).
Summarized, the order of the tasks/notifications is:
- Per-window initialization
- Per-window
browser-delayed-startup-finished
- Once,
sessionstore-windows-restored
- Once,
BrowserGlue
's_scheduleStartupIdleTasks
- Per-window idle tasks without deadline
- Per-window
browser-idle-startup-tasks-finished
- **Once,
BrowserGlue
's_scheduleBestEffortUserIdleTasks
(with a 20 second deadline; long enough to likely be run after tasks without deadline in practice).
GeckoView (geckoview.js) has similar logic, but with some crucial differences:
- Per-window initialization (i.e loading of
geckoview.js
) (note on GeckoView a window has exactly one tab), which schedules the following as idle tasks with a 15 second deadline. - Per-window
browser-delayed-startup-finished
- Per-window
extensions-late-startup
(instead ofbrowser-delayed-startup-finished
) (used inExtensionParent
), introduced in bug 1621503 - Per-window tasks that are the equivalent of
_scheduleBestEffortUserIdleTasks
(=RemoteSecuritySettings.init()
+SafeBrowsing.init()
). - (no other per-window tasks, would be the same as 4)
- Per-window
browser-idle-startup-tasks-finished
- Per-window equivalent of
_scheduleStartupIdleTasks
(remote-startup-requested
andmarionette-startup-requested
)
The significant differences are:
extensions-late-startup
is called multiple times (in practice this doesn't matter, there is a small chance of affecting xpcshell tests that useExtensionParent._resetStartupPromises
).- The order of steps 5 and 7 are swapped (
_scheduleStartupIdleTasks
and_scheduleBestEffortUserIdleTasks
). - The idle tasks (step 5 and 7) run multiple times (once per window) instead of once globally.
One concrete result of this bug is that RemoteSecuritySettings.init
may be called repeatedly, and unnecessarily invoke the updateCertBlocklistener
more than once (because another listener is registered for each call - although the RemoteSettings
constructor returns the same object for a given name, its on
method does not check for duplicates before registering the listener).
Comment 1•3 years ago
|
||
Thank you Rob.
We also have code to track the first initalization here: https://searchfox.org/mozilla-central/source/mobile/android/modules/geckoview/GeckoViewTelemetry.jsm#10 we should probably generalize that and move all the initialize-once method calls there.
Updated•3 years ago
|
Updated•3 years ago
|
Reporter | ||
Updated•3 years ago
|
Updated•3 years ago
|
Description
•