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

refactor(engine-core): replaces vm.context wire connecting/disconnecting #2130

Closed
wants to merge 5 commits into from

Conversation

jodarove
Copy link
Contributor

Details

This PR attempts to simplify the logic of how the wiring is done by encapsulating the connect/disconnect logic into the WireConnector and all context related logic into the ContextWatcher abstractions.

Does this PR introduce breaking changes?

  • No, it does not introduce breaking changes.

@salesforce-best-lwc-internal
Copy link

⚠ Performance Regression

Best has detected that there is a 7.1% performance regression across your benchmarks.

Please click here to see more details.

Click to view significantly changed benchmarks

@lwc/engine-dom

❌ Regressions base (28c8bd3) target (6710b9b) trend
ss-slot-create-container.benchmark/benchmark-slot-ss/synthetic-shadow-create 207.99 (± 1.03ms) 234.24 (± 2.26ms) +26.2ms (12.6%)
ss-slot-update-component-with-slot.benchmark/benchmark-slot-ss/synthetic-shadow-slot-update-component-with-slot 21.96 (± 0.61ms) 23.70 (± 0.62ms) +1.7ms (7.9%)
ss-slot-update-container-template.benchmark/benchmark-slot-ss/synthetic-shadow-slot-update-container-template 21.08 (± 0.35ms) 23.64 (± 0.57ms) +2.6ms (12.2%)
ss-slot-update-slotted-content.benchmark/benchmark-slot-ss/synthetic-shadow-slot-update-slotted-content 142.52 (± 1.70ms) 166.14 (± 2.39ms) +23.6ms (16.6%)
table-append-1k.benchmark/benchmark-table/append/1k 218.51 (± 2.02ms) 243.43 (± 2.99ms) +24.9ms (11.4%)
table-clear-1k.benchmark/benchmark-table/clear/1k 12.10 (± 0.58ms) 13.77 (± 0.21ms) +1.7ms (13.8%)
table-create-1k.benchmark/benchmark-table/create/1k 127.64 (± 1.31ms) 144.09 (± 1.93ms) +16.5ms (12.9%)
table-update-10th-1k.benchmark/benchmark-table/update-10th/1k 113.44 (± 2.18ms) 134.36 (± 2.52ms) +20.9ms (18.4%)
tablecmp-append-1k.benchmark/benchmark-table-component/append/1k 292.95 (± 1.90ms) 352.88 (± 2.29ms) +59.9ms (20.5%)
tablecmp-create-1k.benchmark/benchmark-table-component/create/1k 194.13 (± 0.91ms) 218.37 (± 1.90ms) +24.2ms (12.5%)
tablecmp-update-10th-1k.benchmark/benchmark-table-component/update-10th/1k 101.71 (± 1.14ms) 113.84 (± 0.97ms) +12.1ms (11.9%)
wc-append-1k.benchmark/benchmark-table-wc/append/1k 397.66 (± 2.63ms) 475.60 (± 16.56ms) +77.9ms (19.6%)
wc-clear-1k.benchmark/benchmark-table-wc/clear/1k 19.13 (± 0.62ms) 21.64 (± 0.28ms) +2.5ms (13.1%)
wc-create-10k.benchmark/benchmark-table-wc/create/10k 2606.15 (± 12.81ms) 3027.30 (± 25.13ms) +421.2ms (16.2%)
wc-create-1k.benchmark/benchmark-table-wc/create/1k 304.84 (± 1.75ms) 336.44 (± 2.21ms) +31.6ms (10.4%)
wc-update-10th-1k.benchmark/benchmark-table-wc/update-10th/1k 100.80 (± 1.27ms) 115.28 (± 0.75ms) +14.5ms (14.4%)

@lwc/engine-server

❌ Regressions base (28c8bd3) target (6710b9b) trend
table-render-10k.benchmark/benchmark-table/render/10k 377.45 (± 18.68ms) 512.42 (± 14.57ms) +135.0ms (35.8%)
tablecmp-render-10k.benchmark/benchmark-table-component/render/10k 912.83 (± 16.56ms) 1163.70 (± 16.13ms) +250.9ms (27.5%)

packages/@lwc/engine-core/src/framework/wiring.ts Outdated Show resolved Hide resolved
packages/@lwc/engine-core/src/framework/wiring.ts Outdated Show resolved Hide resolved
Comment on lines 371 to 373
const connector = createConnector(vm, fieldNameOrMethod, wireDef);

wiredConnectors.push(connector);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const connector = createConnector(vm, fieldNameOrMethod, wireDef);
wiredConnectors.push(connector);
wiredConnectors.push(createConnector(vm, fieldNameOrMethod, wireDef));

packages/@lwc/engine-core/src/framework/wiring.ts Outdated Show resolved Hide resolved

// computeConfigAndUpdate already has boundary protection
if (hasDynamicParams) {
Promise.resolve().then(computeConfigAndUpdate);
Copy link
Contributor

Choose a reason for hiding this comment

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

we should probably have this as a utility method somewhere.

Copy link
Contributor

@caridy caridy left a comment

Choose a reason for hiding this comment

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

at first glance it looks cool, but I want to dig deeper, give me more time.

packages/@lwc/engine-core/src/framework/wiring.ts Outdated Show resolved Hide resolved
packages/@lwc/engine-core/src/framework/wiring.ts Outdated Show resolved Hide resolved
computeConfigAndUpdate: () => void;
resetConfigWatcher: () => void;
} {
function createConnector(vm: VM, name: string, wireDef: WireDef): WireConnector {
Copy link
Member

Choose a reason for hiding this comment

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

The amount of closure passing makes the code hard to read. I would convert the connector, config watcher, and context watcher into 3 different classes and pass the object reference around. This would certainly make the code more readable and reduce the overall memory usage due to the closure creation.

Copy link
Contributor

@ravijayaramappa ravijayaramappa left a comment

Choose a reason for hiding this comment

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

🎉 Looking much better. Overall LGTM 👍

packages/@lwc/engine-core/src/framework/vm.ts Outdated Show resolved Hide resolved
packages/@lwc/engine-core/src/framework/wiring.ts Outdated Show resolved Hide resolved
private setNewContext = (newContext: ContextValue) => {
// eslint-disable-next-line lwc-internal/no-invalid-todo
// TODO: dev-mode validation of config based on the adapter.contextSchema
if (this.context !== newContext) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this in an arrow function set into a private field seems like the wrong thing to do.

}

computeConfig() {
return this.configCallback(this.component);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this should have boundary protection.

@ravijayaramappa ravijayaramappa deleted the jodarove/refactor-wiring branch July 22, 2022 17:26
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.

None yet

4 participants