Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/getter-keys-not-computed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@solidjs/babel-plugin": patch
"@solidjs/compiler": patch
---

Emit non-identifier getter keys in compiled props literals as string literals (`get "aria-label"() {}`) instead of computed keys (`get ["aria-label"]() {}`). Same property, but a computed key drops the whole object literal off V8's boilerplate path into per-property runtime definition; on a seven-getter props literal the computed form costs ~45% more to build. Applies to every getter site in both compilers: component props, dynamic element attributes (DOM, SSR, universal).
2 changes: 1 addition & 1 deletion packages/babel-plugin/src/dom/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ function processSpreads(
id,
[],
t.blockStatement([t.returnStatement(expression as babelTypes.Expression)]),
!t.isValidIdentifier(normalized)
false // never computed; see shared/component.ts (#3511)
)
);
} else {
Expand Down
12 changes: 9 additions & 3 deletions packages/babel-plugin/src/shared/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,19 @@ export default function transformComponent(
) {
const expr = transformCondition(attribute.get("value").get("expression"), true);

// Getter keys are never computed: `id` is an identifier or a
// string literal (`get "aria-label"()`), the same property as
// `get ["aria-label"]()` but on V8's object-literal boilerplate
// path — a computed key drops the whole literal to per-property
// runtime definition (#3511). Same at every getter site below
// and in dom/ssr/universal element.ts.
runningObject.push(
t.objectMethod(
"get",
id,
[],
t.blockStatement([t.returnStatement(expr.body)]),
!t.isValidIdentifier(key)
false
)
);
} else if (
Expand All @@ -303,15 +309,15 @@ export default function transformComponent(
? callee.body
: t.blockStatement([t.returnStatement(callee.body)]);

runningObject.push(t.objectMethod("get", id, [], body, !t.isValidIdentifier(key)));
runningObject.push(t.objectMethod("get", id, [], body, false));
} else {
runningObject.push(
t.objectMethod(
"get",
id,
[],
t.blockStatement([t.returnStatement(value.expression as t.Expression)]),
!t.isValidIdentifier(key)
false
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin/src/ssr/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ function createElement(
id,
[],
t.blockStatement([t.returnStatement(expression)]),
!t.isValidIdentifier(key)
false // never computed; see shared/component.ts (#3511)
)
);
} else runningObject.push(t.objectProperty(id, expression));
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin/src/universal/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ function processSpreads(
id,
[],
t.blockStatement([t.returnStatement(expr.body)]),
!t.isValidIdentifier(key)
false // never computed; see shared/component.ts (#3511)
)
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ _$spread(
"margin-right": "40px"
};
},
get ["class"]() {
get class() {
return [
"base",
{
Expand Down Expand Up @@ -603,7 +603,7 @@ _$spread(
[
propsSpread,
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": /* @static */ color()
Expand All @@ -620,7 +620,7 @@ _$spread(
...propsSpread
},
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": /* @static */ color()
Expand All @@ -641,7 +641,7 @@ _$spread(
...propsSpread3
},
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": /* @static */ color()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ _$spread(
"margin-right": "40px"
};
},
get ["class"]() {
get class() {
return [
"base",
{
Expand Down Expand Up @@ -603,7 +603,7 @@ _$spread(
[
propsSpread,
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": /* @static */ color()
Expand All @@ -620,7 +620,7 @@ _$spread(
...propsSpread
},
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": /* @static */ color()
Expand All @@ -641,7 +641,7 @@ _$spread(
...propsSpread3
},
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": /* @static */ color()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const template2 = _$createComponent(Child, {
},
stale: state.data,
handleClick: clickHandler,
get ["hyphen-ated"]() {
get "hyphen-ated"() {
return state.data;
},
ref: el => (e = el)
Expand Down Expand Up @@ -355,7 +355,7 @@ const Template19 = _$createComponent(
_$mergeProps(() => s.dynamic())
);
const Template20 = _$createComponent(Component, {
get ["class"]() {
get class() {
return prop.red ? "red" : "green";
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ _$spread(
"margin-right": "40px"
};
},
get ["class"]() {
get class() {
return [
"base",
{
Expand Down Expand Up @@ -622,7 +622,7 @@ _$spread(
[
propsSpread,
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": /* @static */ color()
Expand All @@ -640,7 +640,7 @@ _$spread(
...propsSpread
},
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": /* @static */ color()
Expand All @@ -662,7 +662,7 @@ _$spread(
...propsSpread3
},
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": /* @static */ color()
Expand Down Expand Up @@ -808,7 +808,7 @@ _$spread(
[
spread,
{
get ["stroke-width"]() {
get "stroke-width"() {
return cond() ? width() : 2;
},
get fill() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const template2 = _$createComponent(Child, {
},
stale: state.data,
handleClick: clickHandler,
get ["hyphen-ated"]() {
get "hyphen-ated"() {
return state.data;
},
ref: el => (e = el)
Expand Down Expand Up @@ -410,7 +410,7 @@ const Template19 = _$createComponent(
_$mergeProps(() => s.dynamic())
);
const Template20 = _$createComponent(Component, {
get ["class"]() {
get class() {
return prop.red ? "red" : "green";
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const template2 = _$createComponent(Child, {
},
stale: state.data,
handleClick: clickHandler,
get ["hyphen-ated"]() {
get "hyphen-ated"() {
return state.data;
},
ref: el => (e = el)
Expand Down Expand Up @@ -350,7 +350,7 @@ const Template19 = _$createComponent(
_$mergeProps(() => s.dynamic())
);
const Template20 = _$createComponent(Component, {
get ["class"]() {
get class() {
return prop.red ? "red" : "green";
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ _$spread(
"margin-right": "40px"
};
},
get ["class"]() {
get class() {
return [
"base",
{
Expand Down Expand Up @@ -605,7 +605,7 @@ _$spread(
[
propsSpread,
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": /* @static */ color()
Expand All @@ -622,7 +622,7 @@ _$spread(
...propsSpread
},
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": /* @static */ color()
Expand All @@ -643,7 +643,7 @@ _$spread(
...propsSpread3
},
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": /* @static */ color()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const template2 = _$createComponent(Child, {
},
stale: state.data,
handleClick: clickHandler,
get ["hyphen-ated"]() {
get "hyphen-ated"() {
return state.data;
},
ref: el => (e = el)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const template = _$ssrElement(
"margin-right": "40px"
};
},
get ["class"]() {
get class() {
return [
"base",
{
Expand Down Expand Up @@ -446,7 +446,7 @@ const template82 = _$ssrElement(
[
propsSpread,
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": color()
Expand All @@ -460,7 +460,7 @@ const template83 = _$ssrElement(
[
propsSpread,
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": color()
Expand All @@ -476,7 +476,7 @@ const template84 = _$ssrElement(
propsSpread2,
propsSpread3,
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": color()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const template2 = Child({
},
stale: state.data,
handleClick: clickHandler,
get ["hyphen-ated"]() {
get "hyphen-ated"() {
return state.data;
},
ref: el => (e = el)
Expand Down Expand Up @@ -269,7 +269,7 @@ const Template18 = Pre({
});
const Template19 = Component(_$mergeProps(() => s.dynamic()));
const Template20 = Component({
get ["class"]() {
get class() {
return prop.red ? "red" : "green";
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const template = _$ssrElement(
"margin-right": "40px"
};
},
get ["class"]() {
get class() {
return [
"base",
{
Expand Down Expand Up @@ -541,7 +541,7 @@ const template82 = _$ssrElement(
[
propsSpread,
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": color()
Expand All @@ -555,7 +555,7 @@ const template83 = _$ssrElement(
[
propsSpread,
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": color()
Expand All @@ -571,7 +571,7 @@ const template84 = _$ssrElement(
propsSpread2,
propsSpread3,
{
get ["data-dynamic"]() {
get "data-dynamic"() {
return color();
},
"data-static": color()
Expand Down Expand Up @@ -641,7 +641,7 @@ const template97 = _$ssrElement(
[
spread,
{
get ["stroke-width"]() {
get "stroke-width"() {
return cond() ? width() : 2;
},
get fill() {
Expand Down
Loading
Loading