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, 1)];
/*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, 1),
api_static_fragment($fragment2, 3),
api_static_fragment($fragment3, 5),
];
/*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, 1)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ 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, 1),
api_static_fragment($fragment2, 3),
api_static_fragment($fragment3, 5),
api_element(
"p",
{
Expand All @@ -49,7 +49,7 @@ function tmpl($api, $cmp, $slotset, $ctx) {
},
[api_text("computed value, should be resolved in component")]
),
api_static_fragment($fragment4(), 8),
api_static_fragment($fragment4, 8),
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, 1),
api_static_fragment($fragment2, 3),
api_static_fragment($fragment3, 5),
api_element("input", {
attrs: {
required: $cmp.computed ? "" : null,
},
props: stc0,
key: 6,
}),
api_static_fragment($fragment4(), 8),
api_static_fragment($fragment4, 8),
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function tmpl($api, $cmp, $slotset, $ctx) {
h: api_element,
} = $api;
return [
api_static_fragment($fragment1(), 1),
api_static_fragment($fragment1, 1),
api_custom_element("x-foo", _xFoo, stc0),
api_element("input", {
attrs: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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, 1),
api_element("input", {
attrs: {
readonly: $cmp.getReadOnly ? "" : null,
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, 1),
api_static_fragment($fragment2, 3),
api_static_fragment($fragment3, 5),
api_static_fragment($fragment4, 7),
];
/*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, 1)];
/*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, 1)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const stc0 = {
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, 1),
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, 1)];
/*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, 1)];
/*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, 1)];
/*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, 1)];
/*LWC compiler vX.X.X*/
}
export default registerTemplate(tmpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function tmpl($api, $cmp, $slotset, $ctx) {
},
key: 0,
}),
api_static_fragment($fragment1(), 2),
api_static_fragment($fragment1, 2),
api_custom_element("ns-bar", _nsBar, {
classMap: stc0,
attrs: stc1,
Expand Down Expand Up @@ -66,7 +66,7 @@ function tmpl($api, $cmp, $slotset, $ctx) {
svg: true,
}),
]),
api_static_fragment($fragment2(), 7),
api_static_fragment($fragment2, 7),
api_element("div", {
className: $cmp.foo,
attrs: stc3,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<div
aria-described-by={scoped}
aria-active-descendant={scoped}
aria-error-message={scoped}
aria-flow-to={scoped}
aria-labelled-by={scoped}
jmsjtu marked this conversation as resolved.
Show resolved Hide resolved
></div>
</template>
Loading
Loading