mirror of
https://github.com/aphrody-labs/oxc.git
synced 2026-10-17 12:56:09 +00:00
perf(packages/codegen): reduce megamorphic type reads in printMemberExpression (#27587)
Perf optimization. Continuation of [#27458](https://github.com/oxc-project/oxc/issues/27458). The object of a computed member expression can be any expression, so reading its `type` is a megamorphic load (a builtin call, which V8 does not deduplicate). Read its `type` once for the `(let)[0]` check, while unwrapping parens, instead of in `withoutParens` and again after it.
This commit is contained in:
1 parent
ff5eae8c5f
commit
b4c8c04b91
1 file changed
+9
-3
@@ -276,9 +276,15 @@ export function printMemberExpression(
|
||||
): void {
|
||||
const { object } = node;
|
||||
if (node.computed) {
|
||||
// `(let)[0]` - a bare `let` object must be wrapped
|
||||
const inner = withoutParens(object);
|
||||
const wrap = inner.type === "Identifier" && inner.name === "let";
|
||||
// `(let)[0]` - a bare `let` object must be wrapped.
|
||||
// `object` can be any expression, so its `type` is a megamorphic load - read it once while unwrapping parens.
|
||||
let inner = object,
|
||||
innerType = inner.type;
|
||||
while (innerType === "ParenthesizedExpression") {
|
||||
inner = (inner as ESTree.ParenthesizedExpression).expression;
|
||||
innerType = inner.type;
|
||||
}
|
||||
const wrap = innerType === "Identifier" && (inner as ESTree.IdentifierReference).name === "let";
|
||||
|
||||
if (wrap) write(state, "(", CAT_OTHER);
|
||||
printExpression(object, state, PREC_POSTFIX, ctx & CTX_FORBID_CALL);
|
||||
|
||||
Reference in new issue
Block a user