perf(javascript): keep one member-effect record per stored fact (#8103)

Member-mutation indexing appended a binding write or escape record for
every traversal state that reached it. States that differ only in
coverage fields the record never stores (origin, owner initializer,
getter widening) produced identical records, and each later receiver
query rescanned all of them. Record each stored fact once, alongside the
existing required-module effect deduplication. Propagation is unchanged.

Effect ordering also re-walked the same top-level statement ancestry for
every candidate record. Cache it with the other initializer positions,
and test the selected path before the costlier receiver comparison.

On the #7774 reproducer the semantic IR and the complete
analyze-javascript-application Evidence are byte-identical, while the
CLI run drops from 146 s to 40 s.

Refs #7774

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kaoru0822andClaude Opus 5.5 authored and GitHub committed 2026-10-30 02:26:01 -07:00
1 parent 6b68fb642a
commit a47dcca010
4 files changed
+184 -38

No files matched your search

@@ -27,6 +27,7 @@ import {
type JavaScriptBindingIndex,
type JavaScriptSemanticBindingState,
type JavaScriptSemanticAnalysisState,
type JavaScriptSemanticMemberEffect,
} from "./javascriptSemanticState.js";
import {
clearSemanticValueCaches,
@@ -522,6 +523,53 @@ export function* collectSemanticMemberMutationsSteps(
effects.push({ path: effectPath, node, kind: effect });
state.requiredModuleEffects.set(identity.specifier, effects);
};
// Traversal states that differ only in coverage fields a record never
// stores, such as the origin, owner initializer or getter widening, reach the
// same binding fact. Each later receiver query scans every record, so retain
// one record per fact. Nodes and initializers compare by identity.
const objectIdentities = new WeakMap<object, number>();
let objectIdentityCount = 0;
const objectIdentity = (value: object | undefined): number | undefined => {
if (value === undefined) return undefined;
let identity = objectIdentities.get(value);
if (identity === undefined) {
identity = objectIdentityCount++;
objectIdentities.set(value, identity);
}
return identity;
};
const recordedBindingEffects = new WeakMap<
JavaScriptSemanticMemberEffect[],
Set<string>
>();
const recordBindingEffect = (
records: JavaScriptSemanticMemberEffect[],
effect: JavaScriptSemanticMemberEffect,
): void => {
const fields: {
readonly [Field in keyof JavaScriptSemanticMemberEffect]-?: unknown;
} = {
path: effect.path,
node: objectIdentity(effect.node),
assignedSources: effect.assignedSources?.map((source) =>
objectIdentity(source),
),
receiverInitializers: effect.receiverInitializers?.map((initializer) =>
objectIdentity(initializer),
),
receiverIdentity: effect.receiverIdentity,
receiverAt: objectIdentity(effect.receiverAt),
};
const key = JSON.stringify(fields);
let recorded = recordedBindingEffects.get(records);
if (recorded === undefined) {
recorded = new Set();
recordedBindingEffects.set(records, recorded);
}
if (recorded.has(key)) return;
recorded.add(key);
records.push(effect);
};
// Ambient indexing owns aliases of global objects. Consume its canonical
// writes instead of reparsing qualified or aliased process assignments.
for (const { path, node } of state.ambientWriteEffects)
@@ -1140,7 +1188,7 @@ export function* collectSemanticMemberMutationsSteps(
// Initializer origins retain the normalized mutation traversal below.
retainsInitializers = receiver?.retainsOrigin !== false;
if (effect === "escape")
binding.escapedPaths.push({
recordBindingEffect(binding.escapedPaths, {
path,
node: mutation,
receiverInitializers,
@@ -1149,7 +1197,7 @@ export function* collectSemanticMemberMutationsSteps(
: { receiverAt: current.memberReadAt ?? current.originAt }),
});
else
binding.memberWrites.push({
recordBindingEffect(binding.memberWrites, {
receiverIdentity: definiteReceiver ? "definite" : "possible",
path,
node: mutation,