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

Reuse a single TreeWalker in nested templates #825

Merged
merged 1 commit into from
Feb 27, 2019

Conversation

jridgewell
Copy link
Contributor

Creating TreeWalkers isn't very optimized, so reusing a single one in the nested templates can speed it up a bit.

https://jsbench.github.io/#d0363ded1753dec3e060e61e1794896b

Creating `TreeWalker`s isn't very optimized, so reusing a single one in the nested templates can speed it up a bit.

https://jsbench.github.io/#d0363ded1753dec3e060e61e1794896b
jridgewell added a commit to jridgewell/lit-html that referenced this pull request Feb 24, 2019
On the heels of lit#825, this unrolls our recursive template processor into
a stack based one.
@justinfagnani
Copy link
Collaborator

I don't care that much about optimizing nested templates, since that should be a pretty rare case and we added support mainly for correctness so lit-html templates didn't blow up with nested templates...

But, if reusing a TreeWalker is that much faster, what if we reused one across the all templates? That could have an impact on real-world code (though I do think we're at the point where DOM mutation operations are dominating costs already).

The Template constructor isn't re-entrant. TemplateResult#_clone shouldn't be either, but I'd want some tests of scenarios like templates with custom elements that synchronously create ShadowRoots under the polyfill, etc.

@jridgewell
Copy link
Contributor Author

But, if reusing a TreeWalker is that much faster, what if we reused one across the all templates? That could have an impact on real-world code

That was the end-goal. 😉

The Template constructor isn't re-entrant. TemplateResult#_clone shouldn't be either, but I'd want some tests of scenarios like templates with custom elements that synchronously create ShadowRoots under the polyfill, etc.

Unfortunately, we're not there yet. #831 has to come first, then we need to fix the reentrancy behavior in insertNodeIntoTemplate, which can fire upgrade/connectedCallback from the insertBefore.

@justinfagnani justinfagnani merged commit 1867fd6 into lit:master Feb 27, 2019
@jridgewell jridgewell deleted the reuse-tree-walker branch February 27, 2019 19:49
jridgewell added a commit to jridgewell/lit-html that referenced this pull request Feb 27, 2019
On the heels of lit#825, this unrolls our recursive template processor into
a stack based one.
jridgewell added a commit to jridgewell/lit-html that referenced this pull request Feb 28, 2019
On the heels of lit#825, this unrolls our recursive template processor into
a stack based one.
justinfagnani pushed a commit that referenced this pull request Mar 1, 2019
On the heels of #825, this unrolls our recursive template processor into
a stack based one.
neuronetio pushed a commit to neuronetio/lit-html that referenced this pull request Dec 2, 2019
Creating `TreeWalker`s isn't very optimized, so reusing a single one in the nested templates can speed it up a bit.

https://jsbench.github.io/#d0363ded1753dec3e060e61e1794896b
neuronetio pushed a commit to neuronetio/lit-html that referenced this pull request Dec 2, 2019
On the heels of lit#825, this unrolls our recursive template processor into
a stack based one.
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