-
Notifications
You must be signed in to change notification settings - Fork 393
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
[Perf] Memoize static objects in template iterator #2559
Labels
Comments
This issue has been linked to a new work item: W-10113376 |
nolanlawson
changed the title
[Perf] Memoize static property bags in template iterator
[Perf] Memoize static objects in template iterator
Nov 1, 2021
nolanlawson
added a commit
that referenced
this issue
Jan 4, 2022
* perf: hoist static object/arrays in templates Fixes #2559 W-10113376 * fix: fix license header * fix: use map size * fix: update packages/@lwc/template-compiler/src/codegen/optimize.ts Co-authored-by: Pierre-Marie Dartus <[email protected]> * fix: remove t.isExpression check * fix: fix typescript * fix: fix vnode shared-object issue * fix: add typescript readonly guard * fix: fix hydration, add more typescript guards * fix: mark more props as readonly * fix: mark another prop as readonly * fix: actually fix innerHTML * fix: mark children as read-only * fix: clone the oldCh array * test: fix snapshot Co-authored-by: Pierre-Marie Dartus <[email protected]>
I'm going to consider this fixed by #2589. We can open new issues for new compile-time optimizations. |
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For a component like this:
The generated template can be optimized by moving duplicated property bags outside of the iteration:
This is similar to #2300, but it's a bit different because the goal is to avoid creating unnecessary duplicate objects in a loop. For instance, the
{ key: 4 }
object doesn't need to be created once per iteration.Based on my tests, this would improve the
dom-table-create-10k
benchmark by 1%-5%.The trick would be to recognize property bags that don't reference any local variables in the iteration function (
row
in this case). E.g. the{ className: row.className, key: api_key(2, row.id) }
object cannot be moved.For property bags that reference getters outside of the iteration (e.g.
$cmp.handleRemove
above), this is an observable change, because the getter won't be called once per iteration. Arguably we can either 1) only optimize truly static data (like{ key: 4 }
), or 2) permit the observable change, as in #2300.The text was updated successfully, but these errors were encountered: