Last Comment Bug 753139 - tab close/open animation should finish in a reasonable amount of time
: tab close/open animation should finish in a reasonable amount of time
Status: NEW
[Snappy:p1]
:
Product: Firefox
Classification: Client Software
Component: Tabbed Browser (show other bugs)
: unspecified
: x86_64 Windows 7
: -- normal with 7 votes (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
Mentors:
Depends on: 790567 731974
Blocks: 593680 815354
  Show dependency treegraph
 
Reported: 2012-05-08 15:11 PDT by (dormant account)
Modified: 2014-12-09 07:41 PST (History)
23 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments

Description (dormant account) 2012-05-08 15:11:38 PDT
Most open/closes seem to take around 100ms, but there is a significant portion of 400+s ones(according to telemetry). On one of my machines tab animation consistently takes ~400ms. We should adjust our animation such that it finishes in a reasonable amount of time even on slower machines.
Comment 1 Jared Wein [:jaws] (please needinfo? me) 2012-05-09 15:30:17 PDT
(In reply to Taras Glek (:taras) from comment #0)
> Most open/closes seem to take around 100ms, but there is a significant
> portion of 400+s ones(according to telemetry).

400+ seconds? or 400+ milliseconds?
Comment 2 (dormant account) 2012-05-09 15:32:04 PDT
(In reply to Jared Wein [:jaws] from comment #1)
> (In reply to Taras Glek (:taras) from comment #0)
> > Most open/closes seem to take around 100ms, but there is a significant
> > portion of 400+s ones(according to telemetry).
> 
> 400+ seconds? or 400+ milliseconds?

ms
Comment 3 (dormant account) 2012-07-19 11:29:01 PDT
CSS transitions are defined in 
http://mxr.mozilla.org/mozilla-central/source/browser/base/content/browser.css#36
Code to measure their duration is in http://dxr.lanedo.com/mozilla-central/browser/base/content/tabbrowser.xml.html#l3294

Jet, why do css transitions that are defined to take a 200-250ms(i'm not clear on how css transitions are declared) range from 3ms to 3seconds?
Comment 4 Vladimir Vukicevic [:vlad] [:vladv] 2012-09-05 16:10:16 PDT
Is there a good testcase for this, or just using the telemetry data?
Comment 5 (dormant account) 2012-09-05 16:34:23 PDT
(In reply to Vladimir Vukicevic [:vlad] [:vladv] from comment #4)
> Is there a good testcase for this, or just using the telemetry data?

1. open a browser with a bunch of about:blank tabs and ctrl+w them. 
2. open about:telemetry, search for FX_TAB_ANIM_CLOSE_MS, observe values in there.
Hardware: I use my amd netbook and i7 mba (both running windows), they seem to average 350-500ms(depending if I'm running the profiler)

See trace from doing ctrl+w of multiple overflow tabs below.
I'm not sure if FX_TAB_ANIM_CLOSE_MS captures *just* the tab CSS transition or if it also captures xul scrollbox overhead(which is huge).
http://people.mozilla.com/~bgirard/cleopatra/?report=0f72d90c38a24d9fe443d0e6cdaff2daa661081e
Comment 6 Vladimir Vukicevic [:vlad] [:vladv] 2012-09-05 16:39:37 PDT
Derp, I use sidebar tabs which doesn't go through our normal tabstrip code so I wasn't seeing this telemetry entry.  I'll try with a new profile and see if my code makes a difference.
Comment 7 Dão Gottwald [:dao] 2012-09-05 16:40:31 PDT
(In reply to Taras Glek (:taras) from comment #5)
> (In reply to Vladimir Vukicevic [:vlad] [:vladv] from comment #4)
> > Is there a good testcase for this, or just using the telemetry data?
> 
> 1. open a browser with a bunch of about:blank tabs and ctrl+w them. 
> 2. open about:telemetry, search for FX_TAB_ANIM_CLOSE_MS, observe values in
> there.
> Hardware: I use my amd netbook and i7 mba (both running windows), they seem
> to average 350-500ms(depending if I'm running the profiler)

If you're interested in meaningful / realistic FX_TAB_ANIM_CLOSE_MS values, you might need to disable the profiler (and make sure you don't run into https://github.com/bgirard/Gecko-Profiler-Addon/issues/21).
Comment 8 Benoit Girard (:BenWa) 2012-09-05 17:09:51 PDT
(In reply to Dão Gottwald [:dao] from comment #7
> If you're interested in meaningful / realistic FX_TAB_ANIM_CLOSE_MS values,
> you might need to disable the profiler (and make sure you don't run into
> https://github.com/bgirard/Gecko-Profiler-Addon/issues/21).

I'm a bit surprised to hear the profiler is impacting performance so much here. Is it particular to this operation or is it in general on windows. At the very worse I'd expect it just simulates a very slightly slower machine which many users have.

Note that the fix for issue 21 has already shipped if you let the extension selfupdate.
Comment 9 (dormant account) 2012-09-06 09:46:32 PDT
(In reply to Benoit Girard (:BenWa) from comment #8)
> (In reply to Dão Gottwald [:dao] from comment #7
> > If you're interested in meaningful / realistic FX_TAB_ANIM_CLOSE_MS values,
> > you might need to disable the profiler (and make sure you don't run into
> > https://github.com/bgirard/Gecko-Profiler-Addon/issues/21).
> 
> I'm a bit surprised to hear the profiler is impacting performance so much
> here. Is it particular to this operation or is it in general on windows. At
> the very worse I'd expect it just simulates a very slightly slower machine
> which many users have.
> 
> Note that the fix for issue 21 has already shipped if you let the extension
> selfupdate.
It has an impact in high-res mode on my slow machine. Either way, even if things run slow that should not cause the 200ms animation to run take 2x longer.
Comment 10 (dormant account) 2012-09-12 01:47:51 PDT
Benoit was looking into using css animation for tab strip. Problem is that animations do not start when the css property is set. 
As I understand: animations are started by the refresh driver. So if there is a lot of jank when the animation is requested(ie event loop is busy), the animation gets scheduled way late...thus ends late too. This is bad.
Comment 11 Dão Gottwald [:dao] 2012-09-12 02:09:26 PDT
(In reply to Taras Glek (:taras) from comment #10)
> Benoit was looking into using css animation for tab strip.

CSS animations or transitions? Note that the open/close animations already use CSS transitions.
Comment 12 Benoit Girard (:BenWa) 2012-09-12 02:42:36 PDT
I'm using transition, transform and translate.
Comment 13 (dormant account) 2012-09-12 02:46:52 PDT
(In reply to Dão Gottwald [:dao] from comment #11)
> (In reply to Taras Glek (:taras) from comment #10)
> > Benoit was looking into using css animation for tab strip.
> 
> CSS animations or transitions? Note that the open/close animations already
> use CSS transitions.

I meant CSS transitions. I also meant doing them in a way that does not jank.
Comment 14 :Ehsan Akhgari (away Aug 1-5) 2012-09-18 19:33:49 PDT
(In reply to Taras Glek (:taras) from comment #10)
> Benoit was looking into using css animation for tab strip. Problem is that
> animations do not start when the css property is set. 
> As I understand: animations are started by the refresh driver. So if there
> is a lot of jank when the animation is requested(ie event loop is busy), the
> animation gets scheduled way late...thus ends late too. This is bad.

Starting the animation immediately would not help a lot in those situations (and it might in fact make things seem worse), since in order to render the second frame we still need to get to the refresh driver.  Well, that's true unless we use OMTC on the desktop, where you would still see a lag if the event loop is busy since the click message needs to be processed first. :(

Is this only a problem because animations start too late?  Or do they actually take longer to finish too with a busy event loop?
Comment 15 :Ehsan Akhgari (away Aug 1-5) 2012-09-18 20:04:57 PDT
So, this got me curious, and I decided to profile this.  Here is a link to a profile which shows what happens if you hold Cmd+T to open tabs one after another.

http://people.mozilla.com/~bgirard/cleopatra/?report=bf5d5e321d9f6db3ad1f0ba435196e1e216c34f1

There's a bunch of bad things that we do:

* First and foremost, we seem to reflow on multiple occasions, which is bad if you expect anything to happen fast!  I filed bug 792296 on what I can say is my pet peeve.  Also filed bug 792297 which is outstanding in itself!
* Things like tabbrowser.xml's updateCurrentBrowser dispatch an event <http://mxr.mozilla.org/mozilla-central/source/browser/base/content/tabbrowser.xml#956> which seems expensive (partly because the addon-sdk code associated with the profiler add-on seems to handle that which is odd!).  Dispatching an event is rather odd since as far as I can tell, the thing which is supposed to get called here is onxblTabSelect in tabbrowser.xml, so perhaps we could just call that method directly?
* newTab.js's init code takes ~8% of the time, but I assume that's going to be fixed when we lazy load about:newtab?
* The stuff happening under tabbrowser's addTab() is particular expensive.

I should also say that I did not look very closely at this profile.  One could potentially dig in much deeper and find yet worse cases.
Comment 16 (dormant account) 2012-09-19 02:30:39 PDT
(In reply to Ehsan Akhgari [:ehsan] from comment #14)
> 
> Starting the animation immediately would not help a lot in those situations
> (and it might in fact make things seem worse), since in order to render the
> second frame we still need to get to the refresh driver.  Well, that's true
> unless we use OMTC on the desktop, where you would still see a lag if the
> event loop is busy since the click message needs to be processed first. :(
The goal here is to not make things smoother. The goal here is to have ui operations complete in a finite-ish amount of time.

> 
> Is this only a problem because animations start too late?  Or do they
> actually take longer to finish too with a busy event loop?

From what I see animation scheduling is fairly precise, bug 731974 should make that better yet.


To illustrate the problem in this bug: <close tab js><request anim><jank><anim start..(maybe hand off to omtc)> will delay the close of the animation by |<jank>|.

We are supposed to drop frames if we can't draw fast enough.
Comment 17 :Ehsan Akhgari (away Aug 1-5) 2012-09-19 11:01:22 PDT
I see.  OK, if we're not talking about smoothness, then what you're saying makes sense.  Although I think there's much more gain to be had by actually optimizing the process of opening and closing tabs than just put things sooner on the event loop, perhaps by extending on my analysis in comment 15.
Comment 18 (dormant account) 2012-09-20 00:37:01 PDT
(In reply to Ehsan Akhgari [:ehsan] from comment #17)
> I see.  OK, if we're not talking about smoothness, then what you're saying
> makes sense.  Although I think there's much more gain to be had by actually
> optimizing the process of opening and closing tabs than just put things
> sooner on the event loop, perhaps by extending on my analysis in comment 15.

Ehsan we are fixing that in parallel(tracked by bug 789573). Jeff & Bas have done a lot of analysis, glad to have you help too.

I'm still waiting to hear a concrete plan on how to address this animation issue from a gfx/layout person.
Comment 19 :Ehsan Akhgari (away Aug 1-5) 2012-09-20 11:16:35 PDT
David knows about animations.
Comment 20 :Ehsan Akhgari (away Aug 1-5) 2012-09-20 11:21:45 PDT
I filed bug 792922 to track the performance of tab opening.
Comment 21 David Baron :dbaron: ⌚️UTC+2 (mostly busy through August 4; review requests must explain patch) 2012-09-20 13:37:42 PDT
(In reply to Taras Glek (:taras) from comment #10)
> As I understand: animations are started by the refresh driver. So if there
> is a lot of jank when the animation is requested(ie event loop is busy), the
> animation gets scheduled way late...thus ends late too. This is bad.

So I think fundamentally what we want to do here is have a way of tying the animation/transition start time to the timeStamp in a DOM event (i.e., the mouse or key event that initiated the operation).

This requires that:
 * DOM events carry time stamps that are in useful interval time (which our implementation does, but doesn't match the spec; see http://lists.w3.org/Archives/Public/www-dom/2012JulSep/0098.html
 * we have an API for setting the start time of a transition or animation to something that comes from an event

The way animations and transitions are currently defined, I don't see a good way to do this.  However, it would probably be more straightforward if we had the API proposed in bug 774655.

Brian Birtles may also have ideas about APIs here.
Comment 22 Brian Birtles (:birtles) 2012-09-23 18:35:31 PDT
(In reply to David Baron [:dbaron] from comment #21)
> Brian Birtles may also have ideas about APIs here.

The Web Animations API should cover this (I say should because I'm not 100% sure of the integration with CSS Transitions since Shane Stephens is working on that and he's on paternity leave).

SMIL also recommends using the event timestamp as the start of the interval for event-based timing, and in discussion with Adobe this sort of issue (exact synchronisation of events and animations) came up a lot and we're suggesting using the event timestamp for that. We'll possibly add a constructor to Web Animations that does this automatically (takes an event and uses its timestamp for the start time, converting it as necessary).

We're currently working on firming up the timing model for Web Animations. I hope implementation will start in a couple of months' time. If that's too late for this bug perhaps we can add an internal API such as David suggested until then.
Comment 23 (dormant account) 2012-09-24 16:53:09 PDT
Is there a reason to not set the animation start time to the time the css animation is setup? Brian, we need something asap.
Comment 24 (dormant account) 2012-10-04 15:24:08 PDT
David and Brian, i see the following options presented in your analyses
1) bug 774655 suggested by David
2) some web animation api suggested by Brian

Since we would like to fix this UI problem soon, 1) seems like the best way forward. Who could work on this?

ps. 
I'm not clear why we can't tweak the definition of when the animation starts. Does the spec explicitly say that animation start should occur on the next browser paint? If not, what limitation prevents this tweak? I'm not clear on why DOM event timestamp non-conformance makes a difference here.
Comment 25 Brian Birtles (:birtles) 2012-10-04 18:07:13 PDT
(In reply to Taras Glek (:taras) from comment #24)
> David and Brian, i see the following options presented in your analyses
> 1) bug 774655 suggested by David
> 2) some web animation api suggested by Brian
> 
> Since we would like to fix this UI problem soon, 1) seems like the best way
> forward. Who could work on this?

Yes, the Web Animations stuff is much longer term. I think (1) is the way to go so long as it remains an internal API (which we can replace with (2) in the future).

> ps. 
> I'm not clear why we can't tweak the definition of when the animation
> starts. Does the spec explicitly say that animation start should occur on
> the next browser paint? If not, what limitation prevents this tweak? I'm not
> clear on why DOM event timestamp non-conformance makes a difference here.

Putting a monotonically-increasing timestamp in the event allows you to compensate for the delay between event dispatch (i.e. when the click actually occurred) and event handling (when you actually triggered the animation).
Comment 26 (dormant account) 2012-10-08 11:28:26 PDT
(In reply to Brian Birtles (:birtles) from comment #25)
> (In reply to Taras Glek (:taras) from comment #24)
> > David and Brian, i see the following options presented in your analyses
> > 1) bug 774655 suggested by David
> > 2) some web animation api suggested by Brian
> > 
> > Since we would like to fix this UI problem soon, 1) seems like the best way
> > forward. Who could work on this?
> 
> Yes, the Web Animations stuff is much longer term. I think (1) is the way to
> go so long as it remains an internal API (which we can replace with (2) in
> the future).
> 
> > ps. 
> > I'm not clear why we can't tweak the definition of when the animation
> > starts. Does the spec explicitly say that animation start should occur on
> > the next browser paint? If not, what limitation prevents this tweak? I'm not
> > clear on why DOM event timestamp non-conformance makes a difference here.
> 
> Putting a monotonically-increasing timestamp in the event allows you to
> compensate for the delay between event dispatch (i.e. when the click
> actually occurred) and event handling (when you actually triggered the
> animation).

So is this a realistic approach we should consider ie #3? Personally I would prefer to fix it this way so websites with similar transition-dependent elements to ours will benefit without having to make use of a new api.
Comment 27 Brian Birtles (:birtles) 2012-10-08 18:15:22 PDT
(In reply to Taras Glek (:taras) from comment #26)
> (In reply to Brian Birtles (:birtles) from comment #25)
> > Putting a monotonically-increasing timestamp in the event allows you to
> > compensate for the delay between event dispatch (i.e. when the click
> > actually occurred) and event handling (when you actually triggered the
> > animation).
> 
> So is this a realistic approach we should consider ie #3? Personally I would
> prefer to fix it this way so websites with similar transition-dependent
> elements to ours will benefit without having to make use of a new api.

Internally we'll still need the new API, and externally too we'll need one eventually (for animations triggered from events but not in a declarative fashion). That's something covered in the Web Animations work, but if I understand correctly, you're proposing we automatically invoke this new API now for animations whose beginning is declaratively associated with an event (e.g. :hover selectors). This would also include storing the monotonically increasing timestamp in the event (but not in the timeStamp attribute since that's epoch time).

David, does CSS allow this kind of automatic adjustment? As I understand it, currently animations are supposed to begin when styles are resolved but is that sufficiently vague that we could automatically compensate for these delays without breaking content?
Comment 28 David Baron :dbaron: ⌚️UTC+2 (mostly busy through August 4; review requests must explain patch) 2012-10-24 11:24:05 PDT
So I think if we had a way to do it it would still be conformant to CSS.

However, I don't think it's realistic.  We do a lot of batching of restyles in ways that means we no longer have a way to track which style changes resulted from which changes.  These batching optimizations are pretty critical to our performance in many cases.  So I think triggering animations based on event times is only something that can happen from cases where the animations are explicitly associated with the event rather than having the connection be a style change.

Note You need to log in before you can comment on or make changes to this bug.