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

Optimize vsync #2451

Merged
merged 1 commit into from
Mar 4, 2016
Merged

Optimize vsync #2451

merged 1 commit into from
Mar 4, 2016

Conversation

cramforce
Copy link
Member

  • use double buffer for task and state arrays.
  • only allocate only promise per frame for measure and run promise.
  • don't allocate state object if not provided (as documentation already said).
  • use same task object shape throughout.
  • allocate one less closure in runPromise

@cramforce
Copy link
Member Author

CC @dvoytenko

*/
run(task, opt_state) {
this.tasks_.push(task);
this.states_.push(opt_state || {});
this.states_.push(opt_state);
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a sizable change to the API. I'd expect something would break. I definitely see some places where default opt_state is used.

Copy link
Member Author

Choose a reason for hiding this comment

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

The documentation states otherwise. No tests fail. Do you have a pointer?

Copy link
Member Author

Choose a reason for hiding this comment

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

I found 2 places. Fixed them up.

This API sucks. Should have just let measure return an object.

- use double buffer for task and state arrays.
- only allocate only promise per frame for measure and run promise.
- don't allocate state object if not provided (as documentation already said).
- use same task object shape throughout.
- allocate one less closure in `runPromise`
@@ -309,6 +334,14 @@ export class Vsync {
tasks[i].mutate(states[i]);
}
}
// Swap last arrays into double buffer.
this.nextTasks_ = tasks;
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 understand the point of having nextTasks_ if we just reassign to tasks and truncate.

Copy link
Member Author

Choose a reason for hiding this comment

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

this.tasks_ can be modified during the loop above, so unless you want want to use a weird splice magic, you need 2 arrays.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ha, I totally read this backwards (as in you're truncating the old nextTasks_, not the new). Never mind.

@jridgewell
Copy link
Contributor

LGTM.

@dvoytenko
Copy link
Contributor

LGTM

cramforce added a commit that referenced this pull request Mar 4, 2016
@cramforce cramforce merged commit 9dccb37 into ampproject:master Mar 4, 2016
@cramforce cramforce deleted the observable-mem branch March 4, 2016 23:23
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.

3 participants