Effects: use requestAnimationFrame timestamp if available #3151
Conversation
There's a typo in your commit message, see the title change I just made. |
Thanks, fixed.
|
} | ||
} | ||
|
||
// We need to be using jQuery.now() or performance.now() consistently as they return different | ||
// values: performance.now() counter starts on page load. | ||
function getTimestamp() { |
dmethvin
Jun 8, 2016
Member
Can we just use jQuery.now()
for all the browsers that don't have the rAF timestamp? Which browsers are affected?
mgol
Jun 8, 2016
Author
Member
This function is also used in createFxNow()
which, I think, is not limited to old browsers?
// We need to be using jQuery.now() or performance.now() consistently as they return different | ||
// values: performance.now() counter starts on page load. | ||
function getTimestamp() { | ||
return window.performance && typeof window.performance.now === "function" ? |
markelog
Jun 9, 2016
•
Member
In what browsers we do not have now
in performance
object?
Also, could you try to use if..else
instead of a ternary?
mgol
Jun 9, 2016
Author
Member
In what browsers we do not have now in performance object?
IE 9, Android <4.4, iOS 7.
And Node.js. :-)
Also, could you try to use if..else instead of a ternary?
Sure.
|
||
// Fake performance.now() returning lower values than Date.now() | ||
// and that its values are fractional. | ||
window.performance.now = function() { |
markelog
Jun 9, 2016
Member
So extrapolating from your comment https://github.com/jquery/jquery/pull/3151/files/c0d05944f93309dc8c0329316d4b6cf699e21d4d#r66414166 it will not break in IE9, but will break in iOS7 and similar envs
mgol
via email
Jun 9, 2016
Author
Member
I am skeptical, since neither gsap nor velocity doing this and there is open tickets in vendor trackers about this |
/cc @gnarf /cc @paulirish since you authored the https://developers.google.com/web/updates/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision?hl=en |
037ce12
to
03d873c
return Date.now() - 99999.6394; | ||
}; | ||
} | ||
|
||
jQuery.now = Date.now; |
mgol
Mar 9, 2017
Author
Member
It turns out it was useful as jQuery.now
is defined as Date.now
so if you mock Date.now
jQuery.now
would remain unmocked.
This is yet another manifestation of how broken our current mocking that happens after jQuery has already loaded & run really is. :/
// We need to be using jQuery.now() or performance.now() consistently as they return different | ||
// values: performance.now() counter starts on page load. | ||
// Support: IE <10, Safari <8.0, iOS <9, Android <4.4, Node with jsdom 9.4 | ||
function getTimestamp() { |
gibson042
Jul 8, 2016
Member
Given the comments, shouldn't we have something more like this?
getTimestamp = window.performance && typeof window.performance.now === "function" ?
// or window.performance.now.bind( window.performance )
jQuery.proxy( window.performance, "now" ) :
jQuery.now;
If the complaint is about testing, then we just need an iframe test in which the sandbox is mocked before loading jQuery.
mgol
Dec 19, 2016
Author
Member
Unfortunately, test setup is run after jQuery is sourced so this would freeze getTimestamp
to use the initial, non-mocked window.performance
.
mgol
Mar 8, 2017
Author
Member
I could put the if
outside of the function definition but that only adds 3 bytes and I suppose such a single if
will not cause any grief for any relatively modern browser.
The fact that we can't reliably mock stuff before jQuery is loaded is obviously a problem but this is an issue bigger than this PR.
@timmywil This is not a new feature so it could move it to |
Did we already agree on landing it? Can we have conformation from mozilla people on this? |
I guess there wasn't a definite decision, only +1s from @dmethvin & @gibson042: https://irc.jquery.org/%23jquery-meeting/default_%23jquery-meeting_20160718.log.html#t12:53:43 There's a patch being prepared for Firefox in https://bugzilla.mozilla.org/show_bug.cgi?id=1278408. |
As I understood the results, it didn't make any browser animate any jerkier. It just didn't help Firefox animate any smoother, but it helped Chrome a lot. If that's the case I'd say it's still good for 3.2. |
My concern with with frames dump, judging by the open tickets and because none of the other animate libraries used it seems issue is still present. So my understanding is that we want to battle test it and ignore accepted practise and vendor bugs? |
If there's a reason that GSAP or Velocity don't use it, we don't currently know that reason. I don't think that's ignoring accepted practice. Who knows, maybe it was too flakey back when they looked at this. @julianshapiro are there specific reasons Velocity doesn't use the rAF timestamp? The only vendor bug I see mentioned is https://bugzilla.mozilla.org/show_bug.cgi?id=1278408 which is just saying that right now this change won't improve Firefox. |
We already received comments from @julianshapiro - #3143 (comment), you want them to be more descriptive? Furthermore we have explanation in description ticket - #3143
This is how currently those animation libs work, i'm not sure if anyone else is doing what we are trying do to, on the contrary, so i'm not sure what do you mean by this
Mm, not sure what do you mean - https://bugzilla.mozilla.org/show_bug.cgi?id=1278408#c0
|
I interpreted the @joliss reply in #3143 (comment) as saying that although dropping frames is worse, @joliss didn't see it dropping frames. |
@mgol I see this as an enhancement, which is closer to a feature than a bug fix, so I prefer it be landed in 3.2. |
I don't think these conditions were met -
That's why I would want to have conformation from the browser people - was it happening? How it looks like? Was it fixed? |
I've removed the "Needs review" label as I first have to debug the Chrome underlying issue (& perhaps report it upstream). |
In some environments that support the requestAnimationFrame timestamp callback parameter using it results in smoother animations. Note: the rAF timestamp is using the same API as performance.now() under the hood so they're compatible with each other. However, some browsers support rAF (with a timestamp parameter) but not performance.now() so using them both would introduce an error. This commit stops using rAF in browsers that don't support performance.now(). From all the browsers jQuery supports this only affects iOS <9 (currently less than 5% of all iOS users) which will now not use rAF. Fixes jquerygh-3143 Closes jquerygh-3151
The PR is not ready so it will need another review later
In some environments that support the requestAnimationFrame timestamp callback parameter using it results in smoother animations. Note: the rAF timestamp is using the same API as performance.now() under the hood so they're compatible with each other. However, some browsers support rAF (with a timestamp parameter) but not performance.now() so using them both would introduce an error. This commit stops using rAF in browsers that don't support performance.now(). From all the browsers jQuery supports this only affects iOS <9 (currently less than 5% of all iOS users) which will now not use rAF. Fixes jquerygh-3143 Closes jquerygh-3151
In some environments that support the requestAnimationFrame timestamp callback parameter using it results in smoother animations. Note: the rAF timestamp is using the same API as performance.now() under the hood so they're compatible with each other. However, some browsers support rAF (with a timestamp parameter) but not performance.now() so using them both would introduce an error. This commit stops using rAF in browsers that don't support performance.now(). From all the browsers jQuery supports this only affects iOS <9 (currently less than 5% of all iOS users) which will now not use rAF. Fixes jquerygh-3143 Closes jquerygh-3151
In some environments that support the requestAnimationFrame timestamp callback parameter using it results in smoother animations. Note: the rAF timestamp is using the same API as performance.now() under the hood so they're compatible with each other. However, some browsers support rAF (with a timestamp parameter) but not performance.now() so using them both would introduce an error. This commit stops using rAF in browsers that don't support performance.now(). From all the browsers jQuery supports this only affects iOS <9 (currently less than 5% of all iOS users) which will now not use rAF. Fixes jquerygh-3143 Closes jquerygh-3151
In some environments that support the requestAnimationFrame timestamp callback parameter using it results in smoother animations. Note: the rAF timestamp is using the same API as performance.now() under the hood so they're compatible with each other. However, some browsers support rAF (with a timestamp parameter) but not performance.now() so using them both would introduce an error. This commit stops using rAF in browsers that don't support performance.now(). From all the browsers jQuery supports this only affects iOS <9 (currently less than 5% of all iOS users) which will now not use rAF. Fixes jquerygh-3143 Closes jquerygh-3151
In some environments that support the requestAnimationFrame timestamp callback parameter using it results in smoother animations. Note: the rAF timestamp is using the same API as performance.now() under the hood so they're compatible with each other. However, some browsers support rAF (with a timestamp parameter) but not performance.now() so using them both would introduce an error. This commit stops using rAF in browsers that don't support performance.now(). From all the browsers jQuery supports this only affects iOS <9 (currently less than 5% of all iOS users) which will now not use rAF. Fixes jquerygh-3143 Closes jquerygh-3151
In some environments that support the requestAnimationFrame timestamp callback parameter using it results in smoother animations. Note: the rAF timestamp is using the same API as performance.now() under the hood so they're compatible with each other. However, some browsers support rAF (with a timestamp parameter) but not performance.now() so using them both would introduce an error. This commit stops using rAF in browsers that don't support performance.now(). From all the browsers jQuery supports this only affects iOS <9 (currently less than 5% of all iOS users) which will now not use rAF. Fixes jquerygh-3143 Closes jquerygh-3151
In some environments that support the requestAnimationFrame timestamp callback parameter using it results in smoother animations. Note: the rAF timestamp is using the same API as performance.now() under the hood so they're compatible with each other. However, some browsers support rAF (with a timestamp parameter) but not performance.now() so using them both would introduce an error. This commit stops using rAF in browsers that don't support performance.now(). From all the browsers jQuery supports this only affects iOS <9 (currently less than 5% of all iOS users) which will now not use rAF. Fixes jquerygh-3143 Closes jquerygh-3151
In some environments that support the requestAnimationFrame timestamp callback parameter using it results in smoother animations. Note: the rAF timestamp is using the same API as performance.now() under the hood so they're compatible with each other. However, some browsers support rAF (with a timestamp parameter) but not performance.now() so using them both would introduce an error. This commit stops using rAF in browsers that don't support performance.now(). From all the browsers jQuery supports this only affects iOS <9 (currently less than 5% of all iOS users) which will now not use rAF. Fixes jquerygh-3143 Closes jquerygh-3151
In some environments that support the requestAnimationFrame timestamp callback parameter using it results in smoother animations. Note: the rAF timestamp is using the same API as performance.now() under the hood so they're compatible with each other. However, some browsers support rAF (with a timestamp parameter) but not performance.now() so using them both would introduce an error. This commit stops using rAF in browsers that don't support performance.now(). From all the browsers jQuery supports this only affects iOS <9 (currently less than 5% of all iOS users) which will now not use rAF. Fixes gh-3143 Closes gh-3151
Summary
In some environments that support the requestAnimationFrame timestamp callback
parameter using it results in smoother animations.
Fixes gh-3143
Currently it's +35 bytes, most likely due to the
getTimestamp
function used increateFxNow()
. Any ideas on how to avoid this size tax?Checklist
Mark an
[x]
for completed items, if you're not sure leave them unchecked and we can assist.New tests have been added to show the fix or feature worksIf needed, a docs issue/PR was created at https://github.com/jquery/api.jquery.comrAF
/Date.now()
Thanks! Bots and humans will be around shortly to check it out.