WebAPPGeneralLifeCycle: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
Line 32: Line 32:
== Gecko Hack ==
== Gecko Hack ==
Apps has various launch time depending on it's content and background tasks.
Apps has various launch time depending on it's content and background tasks.
System app would expect an app goes to ready between 600ms~700ms depending on devices.
So, it is not easy to join transition of system app and splash of a just launched app well
If system app put the launched app in front of homescreen to make it visible, but with opacity near 0; for example, 0.01, the content of the launched app would be rendered and send to compositor at chrome process, but invisible to the user.
since we are not sure of the exact time of the splash being ready, and the non-deterministic of process scheduling makes the problem even harder.
If the launched app has prepared an CSS animation for it's first picture before 700ms and the system app make the app opaque where opacity == 1 at 700ms, the animation of the launched app would play at 700ms.
If we know the longest time required by a just launched app to set a splash,
One problem of this approach is the animation may start at 600ms, or 650ms, not exactly at 700ms. So, a part of the animation at head may not visible for the user. The user will see the animation starts from the middle. The solution is Gecko uses opacity <= 0.01 as an hint for a new/cold launched app.  It don't play animation until the opacity is changed to some value X > 0.01.  So that, for the user, he saw the animation of the launched app is played immediately after the animation of homescreen or system app.
we could do some hack in Gecko to join the transition of system app and the splash animation of a just launched app seamless.
 
For example, a given platform is with 700ms of longest time required by apps, or suggested by the platform.
Then, the apps should set a splash by 700ms.
System would play a transition in 700ms, and expect the splash is played immediately once the transition is stopped.
It is not easy to an app to start a splash exactly at 700ms.
The solution is to set a splash by 700ms, and Gecko does not play it until it is at 700ms.
Once the transition is stopped, Gecko would start playing the splash.


What to change:
What to change:
* Determine how long is enough for cold launched app preparing its first page and animation.  Let's say 700ms.
* Determine how long is enough for cold launched app preparing its first page and animation.  Let's say 700ms.
* System App make new launched app visible at 600ms from launching with opacity value 0.01.
* System App plays a transition of 700ms, and make new launched app foreground and visible when the transition is end.
* Gecko use opacity value <= 0.01 as a hint for a new launched app, never being visible before, postpone all it's animations until it's opacity is changed to a value > 0.01.
* Gecko always paint the content of a new launched app, and send the layer tree from content process to chrome process even if the app is not visible.
* Compositor does not show layers of new launched app who's opacity value is lower than or equal to 0.01.
* Compositor keeps the layer tree and info. attached on layers of a new launch app, but not show it and not play animations until it is foreground or visible.
* Apps prepare a splash animation for it's first page.
* Animations of a new launched app are started at the time being foreground or visible.
* A new launched app is a content process never being foreground or visible since it was created.


Result: The transition of homescreen and app's splash would be connected together seamless.
Result: The transition of homescreen and app's splash would be connected together seamless.

Revision as of 07:25, 2 December 2015

This page tries to create a general model to describe life cycle of all APPs. With this model, we have a well defined and shared set of terminologies to describe performance characters of an APP, and to define a framework for APPs. With terminologies and framework, APPs can be monitored in a stable way, and be continuously improved.

Stages of Life Cycle

  • Launch the App
    • The user touches the homescreen.
    • Request a child process to handle it.
  • Document loading
    • This stage include parsing the first page and javascript, and running javascript for initialization.
      • Keep execution time of scripts here as short as possible.
      • Suggest to put only setTimeout() in |onload| to postpone initialization code until next stage.
      • Load JS files at next stage if possible.
    • The first picture will be showed at end of this stage.
      • Show only minimal static content.
      • No l10n content, or it is showed as empty if there is. (l10n would contribute to the latency of the first picture.)
      • No dynamic content, or is showed with a default state.
      • All content, or icons, are showed if only they don't change their sizes and positions later.
      • An CSS animation on the first picture during data loading may give a better UX; for example, fan-in.
  • Data loading
    • After the completion of document loading.
    • This should be moved out of |onload| event to avoid its callback block rendering of first page. For example, |setTimeout()|.
    • Read data from storage, remote servers, .... etc.
  • Prepare UI
    • Compute with data from the previous stage.
      • Transform, summarize, translate, ... etc.
    • Update the DOM tree to create a picture (frame) to the user.
  • Visual loaded

Load data and Prepare UI could be intermixed.

Gecko Hack

Apps has various launch time depending on it's content and background tasks. So, it is not easy to join transition of system app and splash of a just launched app well since we are not sure of the exact time of the splash being ready, and the non-deterministic of process scheduling makes the problem even harder. If we know the longest time required by a just launched app to set a splash, we could do some hack in Gecko to join the transition of system app and the splash animation of a just launched app seamless.

For example, a given platform is with 700ms of longest time required by apps, or suggested by the platform. Then, the apps should set a splash by 700ms. System would play a transition in 700ms, and expect the splash is played immediately once the transition is stopped. It is not easy to an app to start a splash exactly at 700ms. The solution is to set a splash by 700ms, and Gecko does not play it until it is at 700ms. Once the transition is stopped, Gecko would start playing the splash.

What to change:

  • Determine how long is enough for cold launched app preparing its first page and animation. Let's say 700ms.
  • System App plays a transition of 700ms, and make new launched app foreground and visible when the transition is end.
  • Gecko always paint the content of a new launched app, and send the layer tree from content process to chrome process even if the app is not visible.
  • Compositor keeps the layer tree and info. attached on layers of a new launch app, but not show it and not play animations until it is foreground or visible.
  • Animations of a new launched app are started at the time being foreground or visible.
  • A new launched app is a content process never being foreground or visible since it was created.

Result: The transition of homescreen and app's splash would be connected together seamless.