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

perf: hoist static objects/arrays in templates #2618

Merged
merged 8 commits into from
Feb 4, 2022

Conversation

nolanlawson
Copy link
Collaborator

Details

Un-revert of #2589. Reverts commit 66c0762 (#2617).

This can't be merged until we're ready for the compiler changes.

Does this pull request introduce a breaking change?

  • ✅ No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • ⚠️ Yes, it does include an observable change.

Template compiler has changed.

@nolanlawson
Copy link
Collaborator Author

Rebased on master ^

@nolanlawson

This comment has been minimized.

@salesforce-nucleus

This comment has been minimized.

@nolanlawson
Copy link
Collaborator Author

/nucleus ignore --reason "ui-interaction-explorer-components failing due to object spread"

packages/@lwc/engine-core/src/framework/api.ts Outdated Show resolved Hide resolved
packages/@lwc/engine-core/src/framework/api.ts Outdated Show resolved Hide resolved
packages/@lwc/engine-core/src/framework/api.ts Outdated Show resolved Hide resolved
packages/@lwc/engine-core/src/framework/vnodes.ts Outdated Show resolved Hide resolved
packages/@lwc/engine-core/src/framework/vnodes.ts Outdated Show resolved Hide resolved
packages/@lwc/template-compiler/src/codegen/optimize.ts Outdated Show resolved Hide resolved
@pmdartus
Copy link
Member

pmdartus commented Feb 2, 2022

I am extremely excited by this PR. 🎉
Great job @nolanlawson!

@nolanlawson
Copy link
Collaborator Author

Removing nomerge. This should be safe to merge now.

Copy link
Contributor

@jodarove jodarove left a comment

Choose a reason for hiding this comment

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

@nolanlawson this is great! I only have one suggestion

@@ -588,7 +588,12 @@ function updateDynamicChildren(parentElm: Node, oldCh: VNodes, newCh: VNodes) {
newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm!);
} else {
patchVnode(elmToMove, newStartVnode);
oldCh[idxInOld] = undefined as any;
// Delete the old child, but copy the array since it is read-only.
Copy link
Contributor

@jodarove jodarove Feb 4, 2022

Choose a reason for hiding this comment

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

my intent is to remove (or minimize) this cloning from the codepath, I have some questions:

  1. is it that we declared VNodes readonly for convenience, or that it must be readonly?
  2. if it is for convenience, can we redeclare the type in updateDynamicChildren to receive a Writable?
  3. if it is a must (or we want to be strict with the type), would it help just to clone the array once, instead of multiple times?

My thought process is that we may need to move multiple nodes via this codepath (ex: sort rows in a table), and all this cloning may happen multiple times, when it really needs to happen only once (or not at all).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

1 - Yes it is required. Vnodes is the children array, and it may be shared (due to empty arrays currently, but in the future I'd like static children to be completely shared too).

2 - Hm, the thing is that this code path is very uncommon (it wasn't even covered in any of our Karma tests until I added a test), so we don't want to clone the array every time the function is called. We can certainly clone once (when the codepath is hit), but I don't know if it would actually improve perf in many scenarios, since this scenario is already so rare.

I'll open a separate issue to explore the "only clone once," since I think we need to explore whether it actually improves perf and by how much.

@nolanlawson nolanlawson merged commit dbf80c5 into master Feb 4, 2022
@nolanlawson nolanlawson deleted the nolan/hoist-static-redux branch February 4, 2022 17:15
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