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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌Improve Mediapool initialization by cloning nodes #14055

Merged
merged 9 commits into from Mar 17, 2018

Conversation

alanorozco
Copy link
Member

Cloning nodes is faster than building them, so constructing a seed element makes sense for initialization.

@alanorozco alanorozco requested a review from newmuis March 16, 2018 18:18
@alanorozco alanorozco added this to Incoming (Untriaged) in Stories - By Type via automation Mar 16, 2018
const mediaEl = this.mediaFactory_[type].call(this);
mediaEl.setAttribute('pool-element', elId++);

this.vsync_.mutate(() => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Drive-by: Allocating only one vsync task is another small performance opt.

mediaEl.setAttribute('pool-element', elId++);

this.vsync_.mutate(() => {
for (let i = count; i > 0; i--) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Closure would compile into this faster reverse loop by default. Since i is compared against below the compiler can no longer make order guarantees so it skips the optimization.

const sources = this.getDefaultSource_(type);
mediaEl.setAttribute('pool-element', elId++);
this.enqueueMediaElementTask_(mediaEl,
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'm not sure if we can enqueue this task for the seed and have it also work for the cloned nodes. I didn't wanna perf-test it so I opened #14058

* @private
*/
forEachMediaType_(callback) {
Object.keys(MediaType).forEach(callback);
Copy link
Member Author

Choose a reason for hiding this comment

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

Also just driving by 馃殫...

@alanorozco alanorozco merged commit 1e3da6f into ampproject:master Mar 17, 2018
Stories - By Type automation moved this from Incoming (Untriaged) to Done Mar 17, 2018
@alanorozco alanorozco deleted the mediapool branch March 17, 2018 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants