Skip to content
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

Merged
merged 5 commits into from
Nov 13, 2021

Conversation

jridgewell
Copy link
Contributor

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 the ampdoc 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.

Copy link
Member

@samouri samouri left a 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.

src/service/performance-impl.js Show resolved Hide resolved
src/service/ampdoc-impl.js Show resolved Hide resolved
Copy link
Member

@samouri samouri left a 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

@jridgewell jridgewell merged commit cfa4a27 into ampproject:main Nov 13, 2021
@jridgewell jridgewell deleted the getFirstVisibleTime branch November 15, 2021 20:12
estherkim pushed a commit to estherkim/amphtml that referenced this pull request Nov 17, 2021
…pproject#36273)

* Use timeOrigin for getFirstVisibleTime when page starts visible

* Update old tests

* Add tests for firstVisibleTime

* Fix global conflict

* Fix tests
jridgewell added a commit to jridgewell/amphtml that referenced this pull request Nov 22, 2021
@jridgewell jridgewell mentioned this pull request Nov 22, 2021
jridgewell added a commit that referenced this pull request Nov 22, 2021
* Fix DocInfo tests

Another fix for #36273

* Remove debugger statement

* Lint
jridgewell added a commit to jridgewell/amphtml that referenced this pull request Dec 7, 2021
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.
jridgewell added a commit to jridgewell/amphtml that referenced this pull request Dec 7, 2021
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.
jridgewell added a commit that referenced this pull request Dec 7, 2021
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.
ampprojectbot pushed a commit that referenced this pull request Dec 8, 2021
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants