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

Check for win.performance before using it #6316

Merged
merged 4 commits into from Nov 23, 2016

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Nov 23, 2016

fix #6312

@jridgewell, @aghassemi and I talked about it, and there are other files that use win.performance function. they basically check the existence of win.performance. With this I don't want to create a win.performance polyfill just for performance.now() because it will break their checks.
I decide not to polyfill it here. If we go with polyfilling, I think we should polyfill everything for win.performance

@@ -38,6 +38,8 @@ export const DEFAULT_THRESHOLD =
[0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4,
0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1];

const INIT_TIME = Date.now();
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't pass presubmit as the Date.now() call can't be DCEd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

presubmit is passing locally for me.
Well if I can't do this where should I get the init time? I can create one in IntersectionObserverPolyfill, but what about the export function #getIntersectionChangeEntry?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's lint? Something will fail.

but what about the export function #getIntersectionChangeEntry

First call to calculateChangeEntry sets?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing fails. Is it something with our test? Or do I still need to worry about this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, it's because I'm only checking exports. While this won't be DCEd, it's fine as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool!

@@ -411,7 +413,9 @@ function calculateChangeEntry(
}

return /** @type {!IntersectionObserverEntry} */ ({
time: performance.now(),
time: (typeof performance !== 'undefined' &&
typeof performance.now !== 'undefined') ? performance.now()
Copy link
Contributor

Choose a reason for hiding this comment

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

(performance && performance.now) ? performance.now() : .... The performance.now check is probably unnecessary anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As @aghassemi pointed out #6312 (comment)

for performance.now check. yes it's probably unnecessary. However I see we are doing this check in other places. I thought it would be safer to include the extra check. I am ok with removing it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, yah, it's an unbound global variable if it's not defined. Man that's annoying.

If you keep the performance.now check, no need to typeof it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

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

Is there a real reason to use performance.now? Who really cares about the microsecond precision?

@zhouyx
Copy link
Contributor Author

zhouyx commented Nov 23, 2016

LOL~ I don't think anyone is relying on that value. However that is what native IntersectionObserver returns. I think as long as we don't return Date.now() here, it's ok to be not accurate.

@jridgewell
Copy link
Contributor

I'd vote for the simplified code (and performance win, ironically).

@zhouyx zhouyx merged commit 1bb8712 into ampproject:master Nov 23, 2016
@zhouyx zhouyx deleted the not-polyfill branch November 23, 2016 02:16
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
* git diff HEAD~1

* check performance

* also check for performance.now

* nit
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
* git diff HEAD~1

* check performance

* also check for performance.now

* nit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration tests failing in Safari 8 after #6227
3 participants