On Fri, Apr 12, 2013 at 11:45 AM, James Burke <
jrb...@gmail.com> wrote:
> Possible solution:
>
> What I would like to have instead is a custom "mozapprendered" event.
> Something I could trigger in app logic, since the app knows when its
> UI is actually usable/visible, the system cannot guess it.
Some progress on this, and I would like to figure out if we could land
some of it:
This discussion ended up triggering this ticket:
https://bugzilla.mozilla.org/show_bug.cgi?id=863499
In that ticket and subsequent threads on the whatwg, it seemed like
the front runner was a paired JS API to delay and cancel the delay of
the document load event. I hacked something up for a
document.mozDelayLoadEvent() and document.mozStopDelayingLoadEvent().
A patch for that hack is attached to the above ticket. I will need
some help completing it out though as I am new to platform hacking,
and I want to be sure the error path is correct (see ticket).
But the patch works well enough that I applied to the mozilla-b2g
branch and latest gaia and installed it on an unagi device.
Previously, I noticed some non-app work clogging up the event loop:
https://bugzilla.mozilla.org/show_bug.cgi?id=863870
With the patch applied, and changing the gaia window_manager.js to:
1) hide the app iframe (visibility: hidden) until mozbrowserloadend fires.
2) Also wait for mozbrowserloadend to do screenshot work.
then app code placed on the event loop no longer seems blocked by
non-app work on startup (fixes #863870).
You can confirm this yourself if you apply the 863499 patch to gecko
and use this branch of gaia:
https://github.com/jrburke/gaia/tree/eventloop-screenshot
Run the "Event Loop" and "Event Loop New" test apps and watch the
logcat. The "Event Loop New" app version uses
document.mozDelayLoadEvent where the other app does not. There is
about a 100ms savings in the "new" one for when items placed on the
event loop get to firing, but both apps seem to operate better than
when that ticket was originally filed, closer to a 200ms savings,
comparing original file with the "New" app. I believe the full 200ms
diff is a result of hiding the app iframe until the document load
event fires, holding the document load event until app work is done,
but probably also changes in the platform code since the original
filing.
In that eventloop-screenshot branch, the email app is modified to use
document.mozDelayLoadEvent, and it feels more like an app to have the
screenshot hold for a moment then transition to the live app -- no
white flash, and no partial UI render as more data comes in.
So I would like to figure out:
------------
1) How the 863499 patch could land for gecko, maybe for v1-train?
2) Get more info on the switch to app icon/splashscreen instead of a
screenshot, done in this ticket:
https://bugzilla.mozilla.org/show_bug.cgi?id=866174
3) Any pitfalls if I prep a change in window_manager.js to use
mozbrowserloadend for the screenshot and iframe visibility change?
Perhaps it can be combined with the splash changes: if no screenshot
use the splash image.
On the splash changes in 866174: I expect the motivations were to
reduce load times and non-app work on app startup.
I believe the above changes would give a similar effect, and since the
iframe is hidden, some unnecessary paints could be avoided. It may
also open the window for other optimizations in the platform if we
know the frame is not visible until the mozbrowserloadend event fires.
For the email app, with the event loop cleared of the paints and
screenshot work during app load, I have some other experiments I want
to run to reduce email cold startup.
To give you a feel for how the above changes work with splash screens
and screenshotting+onload changes:
Email, Calendar and Settings with gaia master (has splash screen work
from 866174):
Email:
https://vimeo.com/66368325
Calendar:
https://vimeo.com/66368324
Settings:
https://vimeo.com/66368326
Email, Calendar and Settings with screenshots taken on load, email app
using document.mozDelayLoadEvent:
Email:
https://vimeo.com/66368471
Calendar:
https://vimeo.com/66368472
Settings:
https://vimeo.com/66368470
I believe the Settings app is doing work after onload so there is no
screenshot? So more investigation is needed on that one.
End result though, I believe these changes could avoid white flashes
and "a web page is drawing" feel for apps on startup, and delay
screenshotting until an appropriate time.
James