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: apply static parts optimization to dynamic attributes #4055

Merged
merged 12 commits into from
Mar 19, 2024
3 changes: 2 additions & 1 deletion packages/@lwc/engine-core/src/framework/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ function ssf(slotName: unknown, factory: (value: any, key: any) => VFragment): V
}

// [st]atic node
function st(fragment: Element, key: Key, parts?: VStaticPart[]): VStatic {
function st(fragmentFactory: () => Element, key: Key, parts?: VStaticPart[]): VStatic {
Copy link
Member Author

Choose a reason for hiding this comment

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

This change is needed in the second PR but causes several changes to the template compiler fixtures, see the test fixtures for details.

const owner = getVMBeingRendered()!;
const fragment = fragmentFactory();
const vnode: VStatic = {
type: VNodeType.Static,
sel: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseFragment, registerTemplate } from "lwc";
const $fragment1 = parseFragment`<iframe allow="geolocation https://google-developers.appspot.com"${3}></iframe>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [api_static_fragment($fragment1(), 1)];
return [api_static_fragment($fragment1(), 0)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const $fragment3 = parseFragment`<audio src="http://www.example.com/video.mp3" c
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [
api_static_fragment($fragment1(), 1),
api_static_fragment($fragment2(), 3),
api_static_fragment($fragment3(), 5),
api_static_fragment($fragment1(), 0),
api_static_fragment($fragment2(), 1),
api_static_fragment($fragment3(), 2),
jmsjtu marked this conversation as resolved.
Show resolved Hide resolved
];
/*LWC compiler vX.X.X*/
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseFragment, registerTemplate } from "lwc";
const $fragment1 = parseFragment`<div part="foo"${3}></div>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [api_static_fragment($fragment1(), 1)];
return [api_static_fragment($fragment1(), 0)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ const stc0 = {
props: {
hidden: true,
},
key: 9,
key: 5,
};
const stc1 = {
props: {
hidden: true,
},
key: 10,
key: 6,
};
const stc2 = {
props: {
hidden: true,
},
key: 11,
key: 7,
};
const stc3 = {
props: {
hidden: true,
},
key: 13,
key: 9,
};
function tmpl($api, $cmp, $slotset, $ctx) {
const {
Expand All @@ -36,20 +36,20 @@ function tmpl($api, $cmp, $slotset, $ctx) {
c: api_custom_element,
} = $api;
return [
api_static_fragment($fragment1(), 1),
api_static_fragment($fragment2(), 3),
api_static_fragment($fragment3(), 5),
api_static_fragment($fragment1(), 0),
api_static_fragment($fragment2(), 1),
api_static_fragment($fragment3(), 2),
api_element(
"p",
{
attrs: {
hidden: $cmp.computed ? "" : null,
},
key: 6,
key: 3,
},
[api_text("computed value, should be resolved in component")]
),
api_static_fragment($fragment4(), 8),
api_static_fragment($fragment4(), 4),
api_custom_element("x-foo", _xFoo, stc0, [api_text("boolean present")]),
api_custom_element("x-foo", _xFoo, stc1, [
api_text("empty string, should be true"),
Expand All @@ -64,7 +64,7 @@ function tmpl($api, $cmp, $slotset, $ctx) {
props: {
hidden: $cmp.computed,
},
key: 12,
key: 8,
},
[api_text("computed value, should be resolved in component")]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ const stc1 = {
props: {
required: true,
},
key: 9,
key: 5,
};
const stc2 = {
props: {
required: "",
},
key: 10,
key: 6,
};
const stc3 = {
props: {
required: "other than true",
},
key: 11,
key: 7,
};
const stc4 = {
props: {
required: "3",
},
key: 13,
key: 9,
};
function tmpl($api, $cmp, $slotset, $ctx) {
const {
Expand All @@ -39,17 +39,17 @@ function tmpl($api, $cmp, $slotset, $ctx) {
c: api_custom_element,
} = $api;
return [
api_static_fragment($fragment1(), 1),
api_static_fragment($fragment2(), 3),
api_static_fragment($fragment3(), 5),
api_static_fragment($fragment1(), 0),
api_static_fragment($fragment2(), 1),
api_static_fragment($fragment3(), 2),
api_element("input", {
attrs: {
required: $cmp.computed ? "" : null,
},
props: stc0,
key: 6,
key: 3,
}),
api_static_fragment($fragment4(), 8),
api_static_fragment($fragment4(), 4),
api_custom_element("x-foo", _xFoo, stc1, [api_text("boolean present")]),
api_custom_element("x-foo", _xFoo, stc2, [api_text("empty string")]),
api_custom_element("x-foo", _xFoo, stc3, [api_text("string value")]),
Expand All @@ -60,7 +60,7 @@ function tmpl($api, $cmp, $slotset, $ctx) {
props: {
required: $cmp.computed,
},
key: 12,
key: 8,
},
[api_text("computed value, should be resolved in component")]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const stc0 = {
reversed: "true",
selected: "true",
},
key: 2,
key: 1,
};
function tmpl($api, $cmp, $slotset, $ctx) {
const {
Expand All @@ -28,15 +28,15 @@ function tmpl($api, $cmp, $slotset, $ctx) {
h: api_element,
} = $api;
return [
api_static_fragment($fragment1(), 1),
api_static_fragment($fragment1(), 0),
api_custom_element("x-foo", _xFoo, stc0),
api_element("input", {
attrs: {
readonly: $cmp.getReadOnly ? "" : null,
disabled: "",
title: "foo",
},
key: 3,
key: 2,
}),
];
/*LWC compiler vX.X.X*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const $fragment1 = parseFragment`<p hidden${3}>x</p>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment, h: api_element } = $api;
return [
api_static_fragment($fragment1(), 1),
api_static_fragment($fragment1(), 0),
api_element("input", {
attrs: {
readonly: $cmp.getReadOnly ? "" : null,
disabled: "",
title: "foo",
},
key: 2,
key: 1,
}),
];
/*LWC compiler vX.X.X*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const $fragment4 = parseFragment`<div class="foo bar${0}"${2}></div>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [
api_static_fragment($fragment1(), 1),
api_static_fragment($fragment2(), 3),
api_static_fragment($fragment3(), 5),
api_static_fragment($fragment4(), 7),
api_static_fragment($fragment1(), 0),
api_static_fragment($fragment2(), 1),
api_static_fragment($fragment3(), 2),
api_static_fragment($fragment4(), 3),
];
/*LWC compiler vX.X.X*/
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseFragment, registerTemplate } from "lwc";
const $fragment1 = parseFragment`<section${3}><p data--bar-baz="xyz"${3}></p></section>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [api_static_fragment($fragment1(), 1)];
return [api_static_fragment($fragment1(), 0)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseFragment, registerTemplate } from "lwc";
const $fragment1 = parseFragment`<section${3}><p data-foo="1" data-bar-baz="xyz"${3}></p></section>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [api_static_fragment($fragment1(), 1)];
return [api_static_fragment($fragment1(), 0)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const stc0 = {
content: "",
visible: true,
},
key: 2,
key: 1,
};
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment, c: api_custom_element } = $api;
return [
api_static_fragment($fragment1(), 1),
api_static_fragment($fragment1(), 0),
api_custom_element("foo-bar", _fooBar, stc0),
];
/*LWC compiler vX.X.X*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseFragment, registerTemplate } from "lwc";
const $fragment1 = parseFragment`<input title="\\\\{myValue}"${3}>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [api_static_fragment($fragment1(), 1)];
return [api_static_fragment($fragment1(), 0)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseFragment, registerTemplate } from "lwc";
const $fragment1 = parseFragment`<input type="checkbox" required readonly minlength="5" maxlength="10" checked${3}>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [api_static_fragment($fragment1(), 1)];
return [api_static_fragment($fragment1(), 0)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseFragment, registerTemplate } from "lwc";
const $fragment1 = parseFragment`<section${3}><textarea minlength="1" maxlength="5" unknown-attr="should-error"${3}>x</textarea></section>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [api_static_fragment($fragment1(), 1)];
return [api_static_fragment($fragment1(), 0)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseFragment, registerTemplate } from "lwc";
const $fragment1 = parseFragment`<section${3}><p title="x" aria-hidden="x"${3}>x</p></section>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [api_static_fragment($fragment1(), 1)];
return [api_static_fragment($fragment1(), 0)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const stc2 = {
attrs: {
focusable: "true",
},
key: 4,
key: 3,
svg: true,
};
const stc3 = {
Expand All @@ -37,7 +37,7 @@ function tmpl($api, $cmp, $slotset, $ctx) {
},
key: 0,
}),
api_static_fragment($fragment1(), 2),
api_static_fragment($fragment1(), 1),
api_custom_element("ns-bar", _nsBar, {
classMap: stc0,
attrs: stc1,
Expand All @@ -50,7 +50,7 @@ function tmpl($api, $cmp, $slotset, $ctx) {
tabIndex: "0",
bgColor: "blue",
},
key: 3,
key: 2,
}),
api_element("svg", stc2, [
api_element("use", {
Expand All @@ -62,15 +62,15 @@ function tmpl($api, $cmp, $slotset, $ctx) {
"xx"
),
},
key: 5,
key: 4,
svg: true,
}),
]),
api_static_fragment($fragment2(), 7),
api_static_fragment($fragment2(), 5),
api_element("div", {
className: $cmp.foo,
attrs: stc3,
key: 8,
key: 6,
}),
];
/*LWC compiler vX.X.X*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseFragment, registerTemplate } from "lwc";
const $fragment1 = parseFragment`<somefancytag min="4"${3}></somefancytag>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [api_static_fragment($fragment1(), 1)];
return [api_static_fragment($fragment1(), 0)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseFragment, registerTemplate } from "lwc";
const $fragment1 = parseFragment`<section class="foo bar baz-fiz${0}"${2}></section>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [api_static_fragment($fragment1(), 1)];
return [api_static_fragment($fragment1(), 0)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const $fragment2 = parseFragment`<p${3}>const { foo } = bar;</p>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [
api_static_fragment($fragment1(), 1),
api_static_fragment($fragment2(), 3),
api_static_fragment($fragment1(), 0),
api_static_fragment($fragment2(), 1),
];
/*LWC compiler vX.X.X*/
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseFragment, registerTemplate } from "lwc";
const $fragment1 = parseFragment`<div style="background: blue !important; color: red; opacity: 0.5 !important"${3}></div>`;
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [api_static_fragment($fragment1(), 1)];
return [api_static_fragment($fragment1(), 0)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const $fragment2 = parseFragment`<section style="--my-color: blue; color: var(--
function tmpl($api, $cmp, $slotset, $ctx) {
const { st: api_static_fragment } = $api;
return [
api_static_fragment($fragment1(), 1),
api_static_fragment($fragment2(), 3),
api_static_fragment($fragment1(), 0),
api_static_fragment($fragment2(), 1),
];
/*LWC compiler vX.X.X*/
}
Expand Down
Loading