Skip to content

Use performance.now over Date.now in performance metrics#16119

Merged
alabiaga merged 16 commits intoampproject:masterfrom
alabiaga:16042
Jun 21, 2018
Merged

Use performance.now over Date.now in performance metrics#16119
alabiaga merged 16 commits intoampproject:masterfrom
alabiaga:16042

Conversation

@alabiaga
Copy link
Copy Markdown
Contributor

@alabiaga alabiaga commented Jun 18, 2018

Fixes #16042

  • use performance.now in metrics
  • fix missing jsdocs in performance-impl
  • fix corresponding return types in url-replacements-impl due to jsdoc doc change
  • update amp-access tests to polyfill performance.now as it is not present in a fakeWin
  • update amp-access test to remove pubOrigin expect for 'http' as the pubOrigin for the iframe is now about:src since the fakeLocation is on win.testLocation as opposed to win.location when setting, as win.location on an iframe is not configurable. see describes.js#setup(env)
  • remove opt_disableFallback param in amp-access.js#runAuthorization_() method as it is not used and remove related tests. This change was required as one of the test was failing, and not due to my changes as it fails on master.

@alabiaga alabiaga changed the title Use performance.now over Date.now Use performance.now over Date.now in performance metrics Jun 18, 2018


describes.fakeWin('AccessService multiple sources', {
describes.realWin('AccessService multiple sources', {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the changes in this file?

Copy link
Copy Markdown
Contributor Author

@alabiaga alabiaga Jun 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amp-access tests were failing because performance is not present in a fakeWin

@alabiaga
Copy link
Copy Markdown
Contributor Author

PTAL. updated broken test in amp-access and polyfilled performance.now as opposed to using realWin. Thanks


// Polyfill performance.now() method as it is not available in fakeWin
// environment.
win.performance = {now: () => Date.now()};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also just add it to fake-dom.js#FakeWindow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. thanks!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there are still a bunch of these in this file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right..my editor cache needed to be cleared..for some reason it was showing my updated changes but this file wasn't actually edited. Fixed.


// Polyfill performance.now() method as it is not available in fakeWin
// environment.
win.performance = {now: () => Date.now()};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it ended up needing to be polyfilled in so many places, does it make sense to move this polyfill to env.win so each test doesn't need to repeat the polyfill?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback Kris. Will actually commented on that as well and I made the changes and moved this to fake-dom.js

});
// Polyfill performance.now() method as it would normally not be available
// in a non document environment. Used for tests using fakeWin that rely on
// the performance-impl service.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is slightly out of context and can be updated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would you suggest?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just // Polyfill performance.now with Date.now.. I think most of the current comment is obvious since it's living in FakeWindow.

* @param {function(!Event)} handler
* @param {(boolean|!Object)=} captureOrOpts
*/
/** polyfill addEventListener. */
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why replace the type declarations? Were they causing errors?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes lint errors

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just remove these "polyfill X" comments. They don't add much.

Copy link
Copy Markdown

@dreamofabear dreamofabear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some nits.

* @param {function(!Event)} handler
* @param {(boolean|!Object)=} captureOrOpts
*/
/** polyfill addEventListener. */
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just remove these "polyfill X" comments. They don't add much.

});
// Polyfill performance.now() method as it would normally not be available
// in a non document environment. Used for tests using fakeWin that rely on
// the performance-impl service.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just // Polyfill performance.now with Date.now.. I think most of the current comment is obvious since it's living in FakeWindow.

/** @const */
this.Date = window.Date;

this.setTimeout = function() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc below doesn't seem useful when switching the order like this. We can either add the missing params (prefixed with unused) or remove the JSDoc outright. I think it's fine to remove since they're just standard window APIs.

Ditto below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Thanks

@alabiaga alabiaga merged commit 0d2b567 into ampproject:master Jun 21, 2018
@alabiaga alabiaga deleted the 16042 branch June 21, 2018 14:32
@mattpk
Copy link
Copy Markdown

mattpk commented Jun 21, 2018

@choumx @alabiaga @zhangsu @raywainman

Thanks for addressing the bug so quickly. However, is it okay to just replace Date.now() with performance.now()? Performance.now returns a timestamp relative to performance.timing.navigationStart, which would be orders of magnitude different from Date.now()'s epoch time. Would this break any clients expecting the tick events to provide absolute timestamps?

A potential solution could be to return performance.now() + performance.timing.navigationStart so that the timestamp is still absolute. Alternatively, would it be possible to send the performance.timing.navigationStart value to the client so that we can know what the performance.now() timestamps are relative to? I can file an issue with a request if that sounds feasible.


// Tick the "messaging ready" signal.
this.tickDelta('msr', this.win.Date.now() - this.initTime_);
this.tickDelta('msr', this.win.performance.now() - this.initTime_);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man, this needs to be normalized to an int.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll follow up in a separate PR. good point.

alabiaga added a commit that referenced this pull request Jun 21, 2018
alabiaga added a commit that referenced this pull request Jun 22, 2018
…6227)

* Revert "Revert "Update dependencies for default 🌴 (#16221)"

This reverts commit f8da39e.

* Revert "Mark 4 more visual diff tests as flaky (#16214)"

This reverts commit 867e903.

* Revert "Update dependencies for default 🌴 (#16195)"

This reverts commit 34d1977.

* Revert "Fix selector (#16197)"

This reverts commit f741868.

* Revert "🐛 Position offscreen amp-story-pages using viewport widths (#16092)"

This reverts commit fa85965.

* Revert "Use performance.now over Date.now in performance metrics (#16119)"

This reverts commit 0d2b567.

* fix lint errors

* fix lint error in constructor

* Update performance-impl.js

fix more lint errors

* Update url-replacements-impl.js

more lint..

* Update test-amp-access.js

fix test error.

* Update test-amp-access-source.js

fix more tests...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tick events should use performance.now() over Date.now()

6 participants