perf(javascript): allocate nested evaluation contexts with fixed shapes (#9007)

nestedContext builds one EvaluationContext per recursive expression step. A conditional object spread forces V8 through the generic property-copy path even when the spread adds no fields, and prevents a stable shape. It was the top self-time frame (25.4%) in a profile of semantic indexing.

Use two explicit object literals selected by capturePoint, keeping the same field set, order, values and optionality. Completed analyses are byte-identical across 12 representative sources (36 IR/facts/coverage digests), and member-mutation indexing is 1.47-1.65x faster on the profiled alias-chain workload.

Co-authored-by: Zhenyang Han <mshzy@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-19 22:01:02 -05:00
1 parent 34f3682afd
commit d9df0f9ca2
1 file changed
+20 -11
@@ -1452,20 +1452,29 @@ const mergeValues = (
return merged;
};
// Fixed object shapes avoid copying fields for each nested expression.
const nestedContext = (
context: EvaluationContext,
depth = 1,
): EvaluationContext => ({
state: context.state,
primitiveBindingValues: context.primitiveBindingValues,
...(context.capturePoint === undefined
? {}
: { capturePoint: context.capturePoint }),
expressionDepth: context.expressionDepth + depth,
bindings: context.bindings,
dependence: context.dependence,
memo: context.memo,
});
): EvaluationContext =>
context.capturePoint === undefined
? {
state: context.state,
primitiveBindingValues: context.primitiveBindingValues,
expressionDepth: context.expressionDepth + depth,
bindings: context.bindings,
dependence: context.dependence,
memo: context.memo,
}
: {
state: context.state,
primitiveBindingValues: context.primitiveBindingValues,
capturePoint: context.capturePoint,
expressionDepth: context.expressionDepth + depth,
bindings: context.bindings,
dependence: context.dependence,
memo: context.memo,
};
const isPrimitive = (value: JavaScriptSemanticValue): boolean =>
value.status === "literal" || value.status === "union";