From d9df0f9ca2d5212cec5a11f5eed45c798634a237 Mon Sep 17 00:00:00 2001 From: Zhenyang Han <156560471+mshzy@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:01:02 +0800 Subject: [PATCH] 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 Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> --- .../javascript/javascriptSemanticValues.ts | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/domain/javascript/javascriptSemanticValues.ts b/src/domain/javascript/javascriptSemanticValues.ts index faaefda068..f8fca2de6a 100644 --- a/src/domain/javascript/javascriptSemanticValues.ts +++ b/src/domain/javascript/javascriptSemanticValues.ts @@ -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";