perf(javascript): share one definitions pass and index wrapper IPC dedupe (#3779)

Static analysis rebuilt the full lexical definitions index three times per
file (open receivers, RPC client roots, binding lookup) and the Electron
wrapper pass checked each substituted IPC registration against every prior
finding with JSON.stringify, which is quadratic in registrations.

Classify open receivers and RPC client roots in one traversal over a single
definitions-only index, then extend that same state with ambient writes for
binding lookup. Index IPC findings by side, operation, channel and location
so duplicate checks only consult same-endpoint candidates.

Static facts are byte-identical on the measured corpora.

Refs #3670

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-14 17:59:44 -07:00
1 parent 084e540414
commit 59f528f0e5
8 files changed
+220 -187

No files matched your search

@@ -43,6 +43,19 @@ const callLabel = (node: t.Node): string =>
? callLabel(node.expressions.at(-1) ?? node)
: calleeName(node) || "local call";
const ipcEndpointKey = (value: ElectronIpcFinding): string =>
JSON.stringify([value.side, value.operation, value.channel, value.location]);
const indexIpcFinding = (
index: Map<string, ElectronIpcFinding[]>,
value: ElectronIpcFinding,
): void => {
const key = ipcEndpointKey(value);
const bucket = index.get(key);
if (bucket === undefined) index.set(key, [value]);
else bucket.push(value);
};
interface PathContext {
readonly entryNode: t.Node;
readonly entry: string;
@@ -149,6 +162,16 @@ export const collectElectronWrappedCallPaths = (
) ?? context
);
};
// Duplicate checks consult only facts at the same endpoint and call site.
// Scanning every prior fact made bundles with many registrations quadratic.
let ipcByEndpoint: Map<string, ElectronIpcFinding[]> | undefined;
const ipcAtEndpoint = (): Map<string, ElectronIpcFinding[]> => {
if (ipcByEndpoint !== undefined) return ipcByEndpoint;
ipcByEndpoint = new Map();
for (const { value } of accumulator.ipc)
indexIpcFinding(ipcByEndpoint, value);
return ipcByEndpoint;
};
const hasConditions = (value: SymbolicValue): boolean =>
symbolicVariants(value).some((variant) => variant.conditions?.length);
function* bridgeMemberFunctions(
@@ -351,24 +374,22 @@ export const collectElectronWrappedCallPaths = (
};
// A fully observed transmission stays one source fact when its callback is
// traced. Registrations retain invocation identity because handlers compete.
const duplicate = accumulator.ipc.some(
({ value }) =>
value.side === finding.side &&
value.operation === finding.operation &&
value.channel === channel &&
JSON.stringify(value.location) === JSON.stringify(location) &&
((value.resolution_basis === undefined &&
const invocationKey = JSON.stringify(invocationLocation);
const duplicate = (ipcAtEndpoint().get(ipcEndpointKey(finding)) ?? []).some(
(value) =>
(value.resolution_basis === undefined &&
(value.mode === "send" || value.mode === "invoke")) ||
JSON.stringify(value.invocation_location) ===
JSON.stringify(invocationLocation)),
JSON.stringify(value.invocation_location) === invocationKey,
);
const findingGuarded =
context.conditions.length > 0 || hasConditions(first) || guardedDispatch;
if (!duplicate && !findingGuarded) {
accumulator.ipc.push({
offset: node.start ?? -1,
value: { ...finding, resolution_basis: "wrapper-substitution" },
});
const value: ElectronIpcFinding = {
...finding,
resolution_basis: "wrapper-substitution",
};
accumulator.ipc.push({ offset: node.start ?? -1, value });
indexIpcFinding(ipcAtEndpoint(), value);
if (descriptor.mode !== "send" && descriptor.mode !== "invoke" && !fn)
accumulator.unknownFindings += 1;
} else if (findingGuarded) accumulator.unknownFindings += 1;