-
Notifications
You must be signed in to change notification settings - Fork 400
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(engine): optimize vm object to initialize all the fields in advance #1098
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@caridy @diervo It appears that this change directly results in performance improvement in LGC:
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
@@ -84,10 +83,12 @@ export interface UninitializedVM { | |||
data: VNodeData; | |||
children: VNodes; | |||
velements: VCustomElement[]; | |||
cmpTemplate?: Template; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bulk of the change is here. Initializing the cmpTemplate
and component
. The rest of the PR is just type-cast cleaning.
@@ -158,7 +158,7 @@ export function BaseLightningElement(this: ComponentInterface) { | |||
const vm = vmBeingConstructed; | |||
const { elm, cmpRoot, uid } = vm; | |||
const component = this; | |||
(vm as VM).component = component; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was this transpiling to in typescript?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing: vm.component = component
Except that we don't need to type-casting here since we UnitializedVM
has nullable component
property which wasn't the case before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Details
When the
VM
is initially created in thecreateVM
methods all the properties attached to it are set exceptcmpTemplate
(set inevaluateTemplate
) andcomponent
(set inBaseLightningElement
constructor). By adding all the properties at the creation of the objects, javascript VMs will be able to share the same hidden class for theVM
object through the life cycle of the object.Misc. changes:
UninitalizedVM
type to reflect the addition of the 2 fieldsDoes this PR introduce a breaking change?