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(engine): optimize vm object to initialize all the fields in advance #1098

Merged
merged 5 commits into from
Mar 8, 2019

Conversation

pmdartus
Copy link
Member

@pmdartus pmdartus commented Mar 7, 2019

Details

When the VM is initially created in the createVM methods all the properties attached to it are set except cmpTemplate (set in evaluateTemplate) and component (set in BaseLightningElement constructor). By adding all the properties at the creation of the objects, javascript VMs will be able to share the same hidden class for the VM object through the life cycle of the object.

Misc. changes:

  • Update UninitalizedVM type to reflect the addition of the 2 fields
  • Remove unnecessary type casting

Does this PR introduce a breaking change?

  • Yes
  • No

@salesforce-best-lwc-internal

This comment has been minimized.

@pmdartus pmdartus changed the title perf: optimize vm hidden class be initializing all the fields in advance perf(engine): optimize vm hidden class be initializing all the fields in advance Mar 7, 2019
@pmdartus pmdartus changed the title perf(engine): optimize vm hidden class be initializing all the fields in advance perf(engine): optimize vm object to be initializing all the fields in advance Mar 7, 2019
@pmdartus pmdartus changed the title perf(engine): optimize vm object to be initializing all the fields in advance perf(engine): optimize vm object to initialize all the fields in advance Mar 7, 2019
@salesforce-best-lwc-internal

This comment has been minimized.

@salesforce-best-lwc-internal

This comment has been minimized.

@salesforce-best-lwc-internal

This comment has been minimized.

@pmdartus
Copy link
Member Author

pmdartus commented Mar 7, 2019

@caridy @diervo It appears that this change directly results in performance improvement in LGC:

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: fa645e2 | Target commit: 336d054

lwc-engine-benchmark

table-append-1k metric base(fa645e2) target(336d054) trend
benchmark-table/append/1k duration 150.85 (±4.60 ms) 149.55 (±5.70 ms) -1.3ms (0.9%) 👌
table-clear-1k metric base(fa645e2) target(336d054) trend
benchmark-table/clear/1k duration 10.70 (±0.60 ms) 10.05 (±0.60 ms) -0.6ms (6.1%) 👍
table-create-10k metric base(fa645e2) target(336d054) trend
benchmark-table/create/10k duration 888.90 (±6.00 ms) 872.95 (±6.30 ms) -15.9ms (1.8%) 👍
table-create-1k metric base(fa645e2) target(336d054) trend
benchmark-table/create/1k duration 116.60 (±2.30 ms) 117.85 (±3.05 ms) +1.3ms (1.1%) 👌
table-update-10th-1k metric base(fa645e2) target(336d054) trend
benchmark-table/update-10th/1k duration 85.50 (±1.50 ms) 76.50 (±5.65 ms) -9.0ms (10.5%) 👍
tablecmp-append-1k metric base(fa645e2) target(336d054) trend
benchmark-table-component/append/1k duration 229.20 (±6.85 ms) 226.80 (±10.70 ms) -2.4ms (1.0%) 👌
tablecmp-clear-1k metric base(fa645e2) target(336d054) trend
benchmark-table-component/clear/1k duration 5.75 (±0.85 ms) 5.95 (±0.85 ms) +0.2ms (3.5%) 👌
tablecmp-create-10k metric base(fa645e2) target(336d054) trend
benchmark-table-component/create/10k duration 1772.00 (±10.70 ms) 1749.60 (±8.55 ms) -22.4ms (1.3%) 👍
tablecmp-create-1k metric base(fa645e2) target(336d054) trend
benchmark-table-component/create/1k duration 215.10 (±4.90 ms) 209.95 (±5.60 ms) -5.2ms (2.4%) 👍
tablecmp-update-10th-1k metric base(fa645e2) target(336d054) trend
benchmark-table-component/update-10th/1k duration 66.40 (±4.45 ms) 67.40 (±4.25 ms) +1.0ms (1.5%) 👌
wc-append-1k metric base(fa645e2) target(336d054) trend
benchmark-table-wc/append/1k duration 228.15 (±17.45 ms) 229.05 (±17.60 ms) +0.9ms (0.4%) 👌
wc-clear-1k metric base(fa645e2) target(336d054) trend
benchmark-table-wc/clear/1k duration 10.65 (±1.95 ms) 10.60 (±1.60 ms) -0.1ms (0.5%) 👌
wc-create-10k metric base(fa645e2) target(336d054) trend
benchmark-table-wc/create/10k duration 1882.35 (±10.45 ms) 1865.10 (±12.95 ms) -17.3ms (0.9%) 👍
wc-create-1k metric base(fa645e2) target(336d054) trend
benchmark-table-wc/create/1k duration 225.50 (±4.00 ms) 219.70 (±4.60 ms) -5.8ms (2.6%) 👍
wc-update-10th-1k metric base(fa645e2) target(336d054) trend
benchmark-table-wc/update-10th/1k duration 67.90 (±4.50 ms) 68.70 (±5.50 ms) +0.8ms (1.2%) 👌

@@ -84,10 +83,12 @@ export interface UninitializedVM {
data: VNodeData;
children: VNodes;
velements: VCustomElement[];
cmpTemplate?: Template;
Copy link
Member Author

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;
Copy link
Contributor

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?

Copy link
Member Author

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.

@pmdartus pmdartus merged commit 8b0f9d3 into master Mar 8, 2019
@pmdartus pmdartus deleted the pmdartus/component-shape branch March 8, 2019 06:54
Copy link
Member

@ekashida ekashida left a comment

Choose a reason for hiding this comment

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

Nice!

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.

4 participants