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

fix: simplify style logic in template compiler #314

Merged
merged 5 commits into from
Jun 12, 2018

Conversation

pmdartus
Copy link
Member

Details

  • Simplify the processing logic for inline style in template compiler
  • Make the compiler emit kebab-case CSS properties instead of camelCase and update the engine only use setProperty when patching style.

Fix #227

Does this PR introduce a breaking change?

  • Yes
  • No

@pmdartus pmdartus requested review from caridy and diervo May 17, 2018 21:13
@pmdartus pmdartus force-pushed the pmdartus/fix-invalid-style-parsing branch from 29300d9 to 33236d3 Compare May 17, 2018 22:05
@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 6ad80ca | Target commit: 33236d3

lwc-engine-benchmark

table-append-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table/append/1k duration 151.80 (± 6.00 ms) 145.60 (± 4.70 ms) 4.08% 👍
table-clear-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table/clear/1k duration 11.90 (± 0.50 ms) 12.10 (± 0.50 ms) -1.68% 👌
table-create-10k metric base(6ad80ca) target(33236d3) trend
benchmark-table/create/10k duration 843.60 (± 6.50 ms) 857.40 (± 5.80 ms) -1.64% 👎
table-create-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table/create/1k duration 102.60 (± 1.50 ms) 102.00 (± 1.40 ms) 0.58% 👌
table-update-10th-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table/update-10th/1k duration 90.35 (± 5.55 ms) 86.90 (± 6.40 ms) 3.82% 👌
tablecmp-append-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table-component/append/1k duration 213.10 (± 14.50 ms) 241.80 (± 5.30 ms) -13.47% 👎
tablecmp-clear-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table/clear/1k duration 31.90 (± 1.40 ms) 30.70 (± 1.10 ms) 3.76% 👍
tablecmp-create-10k metric base(6ad80ca) target(33236d3) trend
benchmark-table-component/create/10k duration 1701.20 (± 11.20 ms) 1673.20 (± 7.00 ms) 1.65% 👍
tablecmp-create-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table-component/create/1k duration 192.90 (± 4.10 ms) 188.50 (± 2.70 ms) 2.28% 👍
tablecmp-update-10th-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table-component/update-10th/1k duration 77.50 (± 4.70 ms) 74.80 (± 4.60 ms) 3.48% 👌

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 6ad80ca | Target commit: 33236d3

lwc-engine-benchmark

table-append-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table/append/1k duration 151.80 (± 6.00 ms) 148.20 (± 4.90 ms) 2.37% 👌
table-clear-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table/clear/1k duration 11.90 (± 0.50 ms) 11.80 (± 0.30 ms) 0.84% 👌
table-create-10k metric base(6ad80ca) target(33236d3) trend
benchmark-table/create/10k duration 843.60 (± 6.50 ms) 865.20 (± 7.40 ms) -2.56% 👎
table-create-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table/create/1k duration 102.60 (± 1.50 ms) 102.40 (± 2.00 ms) 0.19% 👌
table-update-10th-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table/update-10th/1k duration 90.35 (± 5.55 ms) 89.50 (± 6.00 ms) 0.94% 👍
tablecmp-append-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table-component/append/1k duration 213.10 (± 14.50 ms) 243.40 (± 4.20 ms) -14.22% 👎
tablecmp-clear-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table/clear/1k duration 31.90 (± 1.40 ms) 32.10 (± 1.60 ms) -0.63% 👌
tablecmp-create-10k metric base(6ad80ca) target(33236d3) trend
benchmark-table-component/create/10k duration 1701.20 (± 11.20 ms) 1702.55 (± 9.45 ms) -0.08% 👌
tablecmp-create-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table-component/create/1k duration 192.90 (± 4.10 ms) 189.10 (± 3.00 ms) 1.97% 👍
tablecmp-update-10th-1k metric base(6ad80ca) target(33236d3) trend
benchmark-table-component/update-10th/1k duration 77.50 (± 4.70 ms) 75.50 (± 5.10 ms) 2.58% 👌

@@ -76,7 +76,7 @@ export interface VNodeData {
props?: Props;
attrs?: Attrs;
class?: Classes;
style?: VNodeStyle;
style?: VNodeStyle | string;
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 mark this as a difference since this file is copied and modified from snabbdom, so we know when copying the new one.

Copy link
Contributor

Choose a reason for hiding this comment

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

... @pmdartus

Copy link
Contributor

Choose a reason for hiding this comment

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

additionally, we can expand this type in LWC only.

Copy link
Member Author

Choose a reason for hiding this comment

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

We will fix this in an upcoming PR when removing the engine registry.

style[name] = cur;
}
if (cur !== (oldStyle as VNodeStyle)[name]) {
style.setProperty(name, cur);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is code copied from snabbdom (mostly). I wonder why did they use style[name] = cur instead of setProperty. was it because of the camelCase?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes the setProperty accepts the kebab-case version of it. While the direct set on the object accepts the camelCase.

I think they want to privilege the camelCase approach because of the developer ergonomic:

// camelCase
h('span', {
  style: {
	border: '1px solid #bada55', 
	fontWeight: 'bold'
  }
}, 'Say my name, and every colour illuminates');

// kebab-case
h('span', {
  style: {
	border: '1px solid #bada55', 
	'font-weight': 'bold'
  }
}, 'Say my name, and every colour illuminates');

But because we don't allow objects for styles, we don't have to deal with the camelCase.

@caridy
Copy link
Contributor

caridy commented May 18, 2018

I still don't trust BEST results. Instead of improving, it is now slower on append operation, which is weird. /cc @diervo

@diervo
Copy link
Contributor

diervo commented May 18, 2018

@caridy you only say you don’t trust best when you don’t agree with the results. I believe using setAtribute is quite expensive compared with assigned it directly so I can understand why the changes really don’t do much

@pmdartus
Copy link
Member Author

It appears that FF and IE11 are (15%) slower when using setProperty instead of a direct property set on the style object. See the benchmark I made: https://esbench.com/bench/5aff0884f2949800a0f61c28

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 6ad80ca | Target commit: 48f9cf4

lwc-engine-benchmark

table-append-1k metric base(6ad80ca) target(48f9cf4) trend
benchmark-table/append/1k duration 151.80 (± 6.00 ms) 146.80 (± 4.50 ms) 3.29% 👍
table-clear-1k metric base(6ad80ca) target(48f9cf4) trend
benchmark-table/clear/1k duration 11.90 (± 0.50 ms) 11.60 (± 0.60 ms) 2.52% 👌
table-create-10k metric base(6ad80ca) target(48f9cf4) trend
benchmark-table/create/10k duration 843.60 (± 6.50 ms) 859.20 (± 6.80 ms) -1.85% 👎
table-create-1k metric base(6ad80ca) target(48f9cf4) trend
benchmark-table/create/1k duration 102.60 (± 1.50 ms) 101.70 (± 1.80 ms) 0.88% 👌
table-update-10th-1k metric base(6ad80ca) target(48f9cf4) trend
benchmark-table/update-10th/1k duration 90.35 (± 5.55 ms) 87.60 (± 3.70 ms) 3.04% 👌
tablecmp-append-1k metric base(6ad80ca) target(48f9cf4) trend
benchmark-table-component/append/1k duration 213.10 (± 14.50 ms) 247.30 (± 3.40 ms) -16.05% 👎
tablecmp-clear-1k metric base(6ad80ca) target(48f9cf4) trend
benchmark-table/clear/1k duration 31.90 (± 1.40 ms) 31.00 (± 1.30 ms) 2.82% 👍
tablecmp-create-10k metric base(6ad80ca) target(48f9cf4) trend
benchmark-table-component/create/10k duration 1701.20 (± 11.20 ms) 1681.30 (± 10.80 ms) 1.17% 👍
tablecmp-create-1k metric base(6ad80ca) target(48f9cf4) trend
benchmark-table-component/create/1k duration 192.90 (± 4.10 ms) 188.90 (± 3.50 ms) 2.07% 👍
tablecmp-update-10th-1k metric base(6ad80ca) target(48f9cf4) trend
benchmark-table-component/update-10th/1k duration 77.50 (± 4.70 ms) 74.30 (± 4.90 ms) 4.13% 👍

@pmdartus
Copy link
Member Author

@caridy Ready for a second pass of review.
I updated the engine and the compiler logic to use camelCased CSS properties.

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.

I'm ok with this now, but I still don't understand why BEST is saying that this is taking 16% more time on update. /cc @diervo

@@ -44,14 +41,8 @@ function updateStyle(oldVnode: VNode, vnode: VNode) {

for (name in newStyle) {
const cur = newStyle[name];
Copy link
Member Author

Choose a reason for hiding this comment

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

Add comment here.

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 119aa7c | Target commit: edf8b41

lwc-engine-benchmark

table-append-1k metric base(119aa7c) target(edf8b41) trend
benchmark-table/append/1k duration 144.60 (± 3.50 ms) 148.40 (± 4.40 ms) -2.63% 👎
table-clear-1k metric base(119aa7c) target(edf8b41) trend
benchmark-table/clear/1k duration 11.30 (± 0.60 ms) 11.60 (± 0.50 ms) -2.65% 👌
table-create-10k metric base(119aa7c) target(edf8b41) trend
benchmark-table/create/10k duration 847.60 (± 8.10 ms) 863.00 (± 6.70 ms) -1.82% 👎
table-create-1k metric base(119aa7c) target(edf8b41) trend
benchmark-table/create/1k duration 100.30 (± 1.30 ms) 101.50 (± 1.80 ms) -1.20% 👎
table-update-10th-1k metric base(119aa7c) target(edf8b41) trend
benchmark-table/update-10th/1k duration 91.10 (± 5.20 ms) 89.90 (± 5.50 ms) 1.32% 👌
tablecmp-append-1k metric base(119aa7c) target(edf8b41) trend
benchmark-table-component/append/1k duration 255.00 (± 5.90 ms) 253.20 (± 2.80 ms) 0.71% 👌
tablecmp-clear-1k metric base(119aa7c) target(edf8b41) trend
benchmark-table/clear/1k duration 35.10 (± 1.30 ms) 34.80 (± 1.20 ms) 0.85% 👌
tablecmp-create-10k metric base(119aa7c) target(edf8b41) trend
benchmark-table-component/create/10k duration 1702.90 (± 9.40 ms) 1728.60 (± 9.10 ms) -1.51% 👎
tablecmp-create-1k metric base(119aa7c) target(edf8b41) trend
benchmark-table-component/create/1k duration 200.20 (± 3.90 ms) 198.80 (± 5.90 ms) 0.70% 👌
tablecmp-update-10th-1k metric base(119aa7c) target(edf8b41) trend
benchmark-table-component/update-10th/1k duration 72.20 (± 4.20 ms) 75.70 (± 4.30 ms) -4.85% 👎

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 119aa7c | Target commit: 5d37713

lwc-engine-benchmark

table-append-1k metric base(119aa7c) target(5d37713) trend
benchmark-table/append/1k duration 144.60 (± 3.50 ms) 144.90 (± 4.20 ms) -0.21% 👌
table-clear-1k metric base(119aa7c) target(5d37713) trend
benchmark-table/clear/1k duration 11.30 (± 0.60 ms) 12.00 (± 0.50 ms) -6.19% 👎
table-create-10k metric base(119aa7c) target(5d37713) trend
benchmark-table/create/10k duration 847.60 (± 8.10 ms) 853.20 (± 4.80 ms) -0.66% 👎
table-create-1k metric base(119aa7c) target(5d37713) trend
benchmark-table/create/1k duration 100.30 (± 1.30 ms) 101.50 (± 1.80 ms) -1.20% 👎
table-update-10th-1k metric base(119aa7c) target(5d37713) trend
benchmark-table/update-10th/1k duration 91.10 (± 5.20 ms) 88.90 (± 5.30 ms) 2.41% 👌
tablecmp-append-1k metric base(119aa7c) target(5d37713) trend
benchmark-table-component/append/1k duration 255.00 (± 5.90 ms) 260.10 (± 3.80 ms) -2.00% 👎
tablecmp-clear-1k metric base(119aa7c) target(5d37713) trend
benchmark-table/clear/1k duration 35.10 (± 1.30 ms) 35.70 (± 1.50 ms) -1.71% 👌
tablecmp-create-10k metric base(119aa7c) target(5d37713) trend
benchmark-table-component/create/10k duration 1702.90 (± 9.40 ms) 1698.30 (± 8.70 ms) 0.27% 👌
tablecmp-create-1k metric base(119aa7c) target(5d37713) trend
benchmark-table-component/create/1k duration 200.20 (± 3.90 ms) 199.30 (± 3.60 ms) 0.45% 👌
tablecmp-update-10th-1k metric base(119aa7c) target(5d37713) trend
benchmark-table-component/update-10th/1k duration 72.20 (± 4.20 ms) 77.70 (± 4.00 ms) -7.62% 👎

@pmdartus
Copy link
Member Author

This PR is now ready to be merged. Waiting for master to stabilize and the new compiler to get deployed before merging.

@caridy
Copy link
Contributor

caridy commented Jun 11, 2018

let's roll @pmdartus

@pmdartus pmdartus merged commit 598d940 into master Jun 12, 2018
@pmdartus pmdartus deleted the pmdartus/fix-invalid-style-parsing branch June 12, 2018 12:00
@apapko apapko mentioned this pull request Jun 14, 2018
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