perf(javascript): skip the repeated-prefix scan on first capture visits (#1789)

Review follow-up. Only a capture already on the alias chain can repeat a prefix, so a first visit no longer slices and serializes every suffix of its path.
This commit is contained in:
Martin Klein
2026-10-11 18:10:13 +08:00
committed by GitHub
parent 262efe6c54
commit 41544fb952
@@ -139,8 +139,15 @@ export function* collectSemanticMemberMutationsSteps(
// same prefix added on every cycle, so exact paths never repeat. When
// that prefix can never be pruned, escaping it once covers every longer
// effect, including writes below shared children.
// Only a capture already on this alias chain can repeat a prefix.
const captureKey = JSON.stringify(capture);
const revisited = current.bindings.has(captureKey);
let repeatedPrefix: PropertyPath | undefined;
for (let start = 1; start <= current.path.length; start++) {
for (
let start = 1;
revisited && start <= current.path.length;
start++
) {
const suffix = current.path.slice(start);
if (!current.bindings.has(JSON.stringify([...capture, suffix])))
continue;
@@ -240,7 +247,7 @@ export function* collectSemanticMemberMutationsSteps(
const primitiveWrite =
value?.status === "literal" || value?.status === "union";
recordedEffects.add(identity);
const nested = new Set([...current.bindings, lifetime]);
const nested = new Set([...current.bindings, lifetime, captureKey]);
const origins =
current.originAt === undefined
? binding