Reduce stalls when opening large diffs (#4574)

* perf(app): reduce avoidable work when opening large diffs

Large snapshots were recursively reconstructed for reference stability, while native scroll worklets captured complete file models. Preserve identity at the data producers and prepare text for the visible window without rebuilding unchanged files.

* test(app): await commit diff query completion without polling

* chore(app): remove profiling artifacts from the source tree
This commit is contained in:
Mohamed Boudra
2026-09-09 16:05:44 +02:00
committed by GitHub
parent 0b3d82a469
commit d311797653
21 changed files with 816 additions and 163 deletions
@@ -78,6 +78,40 @@ function modelInput(
}
describe("diff document workspace cache", () => {
it("keeps text prepared in each visited window of the same file", () => {
const cache = createDiffDocumentWorkspaceCache();
const source = diffFile();
source.hunks[0]!.lines = Array.from({ length: 100 }, (_, index) => ({
type: "add",
content: `const value${index} = ${index};`,
}));
const { measureText, stats } = countingMeasurer();
const input = modelInput([source], measureText);
for (const top of [30, 300, 600]) {
cache.buildModel({ ...input, materializationWindow: { top, height: 54 } });
}
stats.calls = 0;
cache.buildModel({ ...input, materializationWindow: { top: 300, height: 54 } });
expect(stats.calls).toBe(0);
});
it("retains text cells for unchanged files when another file changes", () => {
const cache = createDiffDocumentWorkspaceCache();
const { measureText } = countingMeasurer();
const files = [diffFile(), { ...diffFile(), path: "b.ts" }];
const first = cache.buildModel(modelInput(files, measureText));
const replacement = structuredClone(files[0]!);
replacement.hunks[0]!.lines[0]!.content = "changed text";
const next = cache.buildModel(modelInput([replacement, files[1]!], measureText));
const oldRow = first.rows[first.files[1]!.rowStart]!;
const nextRow = next.rows[next.files[1]!.rowStart]!;
expect(oldRow.kind).toBe("line");
expect(nextRow.kind).toBe("line");
if (oldRow.kind !== "line" || nextRow.kind !== "line") throw new Error("Missing file text");
expect(nextRow.cells).toBe(oldRow.cells);
expect(next.files[0]!.file).toBe(replacement);
});
it("reuses measured rows until a model-building input changes", () => {
const cache = createDiffDocumentWorkspaceCache();
const files = [diffFile()];
@@ -115,7 +149,7 @@ describe("diff document workspace cache", () => {
stats.calls = 0;
cache.buildModel({ ...input, files: [...files] });
expect(stats.calls).toBeGreaterThan(0);
expect(stats.calls).toBe(0);
});
it("bounds retained geometry variants for one diff payload", () => {
@@ -152,7 +186,7 @@ describe("diff document workspace cache", () => {
const files = [diffFile(), { ...diffFile(), path: "src/b.ts" }];
const { measureText, stats } = countingMeasurer();
const first = cache.buildModel(
modelInput(files, measureText, { materializationWindow: { top: 0, height: 20 } }),
modelInput(files, measureText, { materializationWindow: { top: 30, height: 20 } }),
);
const firstCalls = stats.calls;
const secondFile = first.files[1]!;