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

Delay Penalized Elements After First Visible Time #2671

Merged
merged 3 commits into from
Mar 25, 2016

Conversation

jridgewell
Copy link
Contributor

In the first moments after first visible time, we will delay penalized elements (based on their element priority).

If the document has already been visible for a while, no penalty will be added.

Fixes #2561.

[Perf](http://jsperf.com/date-now-vs-new-date/20) is better, and it’s
[supported in everything >= IE
9](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo
bal_Objects/Date/now#Browser_compatibility)
@@ -47,8 +47,7 @@ export class Timer {
* @return {number}
*/
now() {
// TODO(dvoytenko): when can we use Date.now?
return Number(new Date());
return 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.

👍

@dvoytenko
Copy link
Contributor

@jridgewell conceptually looks great and, as mentioned offline, I believe this solves more than one problem.

@jridgewell
Copy link
Contributor Author

PTAL.

Should we be adding an integration test for this?

if (this.exec_.getSize() == 0) {
return 0;
if (this.firstVisibleTime_ === -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just add comments here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Commented.

@dvoytenko
Copy link
Contributor

@jridgewell Would like more integration tests for resources.js in general, but not really this case - it plays very well on the execution timeout and was always meant to be very unit-testable.

@@ -126,6 +126,11 @@ describe('Resources', () => {
expect(resources.calcTaskTimeout_(task_p0)).to.equal(0);
expect(resources.calcTaskTimeout_(task_p1)).to.equal(0);

// Idle render penalty after first visible
resources.firstVisibleTime_ = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a test for firstVisibleTime_ == -1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's implicit in the "Empty pool" tests above. Would you like me to add the explicit resources.firstVisibleTime_ = -1 there?

Copy link
Contributor

Choose a reason for hiding this comment

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

No problem then.

@dvoytenko
Copy link
Contributor

@jridgewell This is all good. I'm pretty much at LGTM. Just couple of comments - please address and I'll do another pass tomorrow morning.

return 0;
// If we've never been visible, return 0. This follows the previous
// behavior of not delaying tasks when there's nothing to do.
// TODO(jridgewell): Should we return an un-subtracted `penalty` here?
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think TODO is needed here. The processing is done via two queues: scheduling and execution. We delay execution here which is fine. If we have an issue with INVISIBLE mode - that should be addressed in scheduling and it already is - i.e. we do not schedule elements unless they opt-in and close to viewport, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@dvoytenko
Copy link
Contributor

LGTM with one last comment.

In the first moments after first visible time, we will delay penalized
elements (based on their element priority). Once the document has been
visible for more than the element’s priority delay, we allow them to
run.
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.

2 participants