-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Use timeOrigin for getFirstVisibleTime when page starts visible #36273
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @jridgewell for tracking this down!
Fixing visible time calculation within Ampdoc
provides a more robust fix for #34383. We can also slightly simplify the implementation of tickSinceVisible_
now, by removing the conditional around visibleTime calculation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful stuff. I still think theres an opportunity to simplify the tickSinceVisible
function now, but thats a nit
61008c3
to
58627a7
Compare
58627a7
to
1ef1d1a
Compare
…pproject#36273) * Use timeOrigin for getFirstVisibleTime when page starts visible * Update old tests * Add tests for firstVisibleTime * Fix global conflict * Fix tests
Another fix for ampproject#36273
* Fix DocInfo tests Another fix for #36273 * Remove debugger statement * Lint
In ampproject#36273, I switched from `Date.now()` to `performance.now()`, thinking it was a higher resolution timestamp time since the unix epoch. But, `peformance.now` is relative to _page load time_ (or `timeOrigin`), not the epoch. This matters because our "since visible" metrics use the epoch as their base time, meaning the timestamps are roughly 1.6 trillion milliseconds. But `performance.now` is tiny, in the range of a few million for a page that was loaded an hour ago. When we calculated the "since visible", we received values that were still in the trillions when we expect millions. By adding `performance.now()` and `performance.timeOrigin`, we get a timestamp relative to the epoch. Now when we calculate the "since visible", we get the correct values.
In ampproject#36273, I switched from `Date.now()` to `performance.now()`, thinking it was a higher resolution timestamp time since the unix epoch. But, `peformance.now` is relative to _page load time_ (or `timeOrigin`), not the epoch. This matters because our "since visible" metrics use the epoch as their base time, meaning the timestamps are roughly 1.6 trillion milliseconds. But `performance.now` is tiny, in the range of a few million for a page that was loaded an hour ago. When we calculated the "since visible", we received values that were still in the trillions when we expect millions. By adding `performance.now()` and `performance.timeOrigin`, we get a timestamp relative to the epoch. Now when we calculate the "since visible", we get the correct values.
In #36273, I switched from `Date.now()` to `performance.now()`, thinking it was a higher resolution timestamp time since the unix epoch. But, `performance.now` is relative to _page load time_ (or `performance.timeOrigin`), not the epoch. This matters because our "since visible" metrics use the epoch as their base time, meaning the timestamps are roughly 1.6 trillion milliseconds. But `performance.now` is tiny, in the range of a few million for a page that was loaded an hour ago. When we calculated the "since visible", we received values that were still in the trillions when we expect millions. By adding `performance.now()` and `performance.timeOrigin`, we get a timestamp relative to the epoch. Now when we calculate the "since visible", we get the correct values.
In #36273, I switched from `Date.now()` to `performance.now()`, thinking it was a higher resolution timestamp time since the unix epoch. But, `performance.now` is relative to _page load time_ (or `performance.timeOrigin`), not the epoch. This matters because our "since visible" metrics use the epoch as their base time, meaning the timestamps are roughly 1.6 trillion milliseconds. But `performance.now` is tiny, in the range of a few million for a page that was loaded an hour ago. When we calculated the "since visible", we received values that were still in the trillions when we expect millions. By adding `performance.now()` and `performance.timeOrigin`, we get a timestamp relative to the epoch. Now when we calculate the "since visible", we get the correct values. (cherry picked from commit 7645c4e)
When comparing the LCP and LCPV scores for viewer-embedded pages that are immediately visible, I noticed the LCPV scores were considerably lower. This seems wrong, if the page is immediately visible, the LCP and LCPV should be equivalent.
I think this is because the
ampdoc
keeps track of the time the page is first visible, but that's initialized in JS when theampdoc
is first created. That means we don't notice the parse+exec time that it takes to reach that point, and the LCPV is better than reality.