Skip to content

Commit 64003a8

Browse files
sammooreclaude
andcommitted
perf(native): unwrap a transform argument without a second style-function test
argument() unwraps each one-token argument of translate(), scale() and rotate() with isStyleDescriptorArray, whose isStyleFunction runs Object.keys, and resolveValue then runs the same test on the token. An argument is always a compiled descriptor, where only a style function starts with its {} marker, so an array of one entry that isn't a plain object is an item, and typeof and Array.isArray tell them apart. On Hermes (list-bench, against bench), Tailwind's translate-x-4 rotate-45 scale-110 with its variables resolved at runtime goes from +6.1% to +1.6%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D4jU1dW7KKQntNrr9i2xGi
1 parent e36030c commit 64003a8

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎src/native/styles/functions/transform-functions.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ export const translate: StyleFunctionResolver = (resolveValue, descriptor) => {
8888

8989
/** A comma-separated argument list holds each argument as the array of its tokens */
9090
function argument(resolveValue: SimpleResolveValue, arg: StyleDescriptor) {
91+
// A descriptor, never a resolved value: a style function starts with its {}
92+
// marker, so an array of one entry that isn't a plain object is an item.
93+
// This skips isStyleFunction's Object.keys, which resolveValue runs anyway
94+
const token = Array.isArray(arg) && arg.length === 1 ? arg[0] : undefined;
9195
return resolveValue(
92-
isStyleDescriptorArray(arg) && arg.length === 1 ? arg[0] : arg,
96+
token !== undefined && (typeof token !== "object" || Array.isArray(token))
97+
? token
98+
: arg,
9399
);
94100
}

0 commit comments

Comments
 (0)