perf(analysis-view): count JavaScript fact group nodes without retaining ID sets (#15261)

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
ShuaixinHuangandVincent Koc authored and GitHub committed 2026-12-01 00:33:34 +08:00
1 parent 7bedbcb6f6
commit 88eaed6fa7
2 files changed
+45 -4

No files matched your search

+11 -4
View File
@@ -541,7 +541,8 @@ export const projectJavaScriptFactGroups = (
{
readonly properties: FactGroupRow["properties"];
observations: number;
readonly nodes: Set<string>;
nodeCount: number;
lastNodeId: string;
}
>();
forEachMatchingFact(
@@ -568,11 +569,17 @@ export const projectJavaScriptFactGroups = (
groups.set(identity, {
properties,
observations: 1,
nodes: new Set([node.node_id]),
nodeCount: 1,
lastNodeId: node.node_id,
});
else {
existing.observations += 1;
existing.nodes.add(node.node_id);
// Matching facts follow graph order, where each node ID is unique and
// all observations for that node are contiguous.
if (existing.lastNodeId !== node.node_id) {
existing.nodeCount += 1;
existing.lastNodeId = node.node_id;
}
}
},
);
@@ -582,7 +589,7 @@ export const projectJavaScriptFactGroups = (
.map(([, group]) => ({
properties: group.properties,
observation_count: group.observations,
node_count: group.nodes.size,
node_count: group.nodeCount,
}));
return { rows, total: groups.size };
};
@@ -1,3 +1,9 @@
import {
javascriptFactGroupsViewRequestSchema,
projectJavaScriptFactGroups,
} from "../../../src/domain/analysisView/javascriptFactsView.js";
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
import { freezeOwnedJsonTreeSnapshot } from "../../../src/domain/immutableJson.js";
import { withCanonicalOutputSchema } from "../../fixtures/canonicalOutputSchema.js";
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
@@ -116,6 +122,34 @@ it("counts distinct retained IPC channels per operation and reads one group's ob
]);
expect(groups.coverage).toMatchObject({ total: 4, exhausted: true });
const byOperation = javascriptFactGroupsViewRequestSchema.parse({
kind: "javascript-fact-groups",
where: { ...where, paths: ["preload.js", "main.js"] },
group_by: ["operation"],
});
const retained = harness.session.evidenceForAnalysis(source.evidence_id);
const analysis = freezeOwnedJsonTreeSnapshot(
javascriptApplicationAnalysisResultSchema.parse(
retained?.normalized_result,
),
);
const indexed = projectJavaScriptFactGroups(
analysis.graph.nodes,
byOperation,
analysis,
);
const linear = projectJavaScriptFactGroups(analysis.graph.nodes, byOperation);
expect(indexed).toEqual(linear);
const operations = await view(byOperation);
if (operations.kind !== "javascript-fact-groups")
throw new Error("Expected operation groups");
expect(operations.rows).toEqual(indexed.rows);
expect(operations.rows).toContainEqual({
properties: { operation: "send" },
observation_count: 4,
node_count: 3,
});
const sends = await view({
kind: "javascript-fact-groups",
where: {