From 0ff2742e22978ab41464346fdf5d71d5962928f8 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Tue, 20 Oct 2026 16:01:09 -0500 Subject: [PATCH 1/2] perf(server): sort the working-tree file list once per status read The local status read sorted the numstat files, appended files that have no numstat (untracked paths), then sorted the whole list again. The final sort alone gives the same order, so drop the first one. The new test spies on Array sort calls during a status read with tracked text, binary and untracked files. It checks the returned files and totals, and that the file list is sorted in one pass. On main it sees two passes ([5, 3]). Co-Authored-By: Claude Opus 5.5 --- apps/server/src/vcs/GitVcsDriverCore.test.ts | 52 ++++++++++++++++++++ apps/server/src/vcs/GitVcsDriverCore.ts | 12 ++--- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts index eef44e9c02c80..5834100354572 100644 --- a/apps/server/src/vcs/GitVcsDriverCore.test.ts +++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts @@ -4,6 +4,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices"; import * as HostProcess from "@t3tools/shared/HostProcess"; import { writeFakeCli } from "@t3tools/provider-testing/fakeCli"; import { assert, it, describe } from "@effect/vitest"; +import { vi } from "vite-plus/test"; import * as Deferred from "effect/Deferred"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; @@ -3359,6 +3360,57 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => { }), ); + it.effect("sorts changed files once after adding files without numstat", () => + Effect.gen(function* () { + const cwd = yield* makeTmpDir(); + yield* initRepoWithCommit(cwd); + yield* writeTextFile(cwd, "d.txt", "one\n"); + yield* writeTextFile(cwd, "c.bin", "binary\0one"); + yield* writeTextFile(cwd, "b.txt", "one\n"); + yield* git(cwd, ["add", "."]); + yield* git(cwd, ["commit", "-m", "add files"]); + yield* writeTextFile(cwd, "d.txt", "two\n"); + yield* writeTextFile(cwd, "c.bin", "binary\0two"); + yield* writeTextFile(cwd, "b.txt", "one\ntwo\n"); + yield* writeTextFile(cwd, "e-new.txt", "new\n"); + yield* writeTextFile(cwd, "a-new.txt", "new\n"); + const driver = yield* GitVcsDriver.GitVcsDriver; + const sorts = [vi.spyOn(Array.prototype, "sort"), vi.spyOn(Array.prototype, "toSorted")]; + const sortedLists: Array> = []; + + const status = yield* driver.statusDetailsLocal(cwd).pipe( + Effect.ensuring( + Effect.sync(() => { + for (const sort of sorts) { + // Read the recorded receivers first: mockRestore clears them. + sortedLists.push(...sort.mock.contexts.filter((list) => Array.isArray(list))); + sort.mockRestore(); + } + }), + ), + ); + + assert.deepEqual(status.workingTree.files, [ + { path: "a-new.txt", insertions: 0, deletions: 0 }, + { path: "b.txt", insertions: 1, deletions: 0 }, + { path: "c.bin", insertions: 0, deletions: 0 }, + { path: "d.txt", insertions: 1, deletions: 1 }, + { path: "e-new.txt", insertions: 0, deletions: 0 }, + ]); + assert.equal(status.workingTree.insertions, 2); + assert.equal(status.workingTree.deletions, 1); + // Every array sorted while reading status that holds a returned file entry. + const statusFiles = new Set(status.workingTree.files); + const fileListSorts = sortedLists.filter((list) => + list.some((file) => statusFiles.has(file)), + ); + assert.deepEqual( + fileListSorts.map((list) => list.length), + [status.workingTree.files.length], + ); + }), + ); + it.effect("commits selected files from a nested project directory", () => Effect.gen(function* () { const path = yield* Path.Path; diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts index 64ce4024edd69..42a02a2dc3ed9 100644 --- a/apps/server/src/vcs/GitVcsDriverCore.ts +++ b/apps/server/src/vcs/GitVcsDriverCore.ts @@ -2221,13 +2221,11 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* let insertions = 0; let deletions = 0; - const files = Array.from(fileStatMap.entries()) - .map(([filePath, stat]) => { - insertions += stat.insertions; - deletions += stat.deletions; - return { path: filePath, insertions: stat.insertions, deletions: stat.deletions }; - }) - .toSorted((a, b) => a.path.localeCompare(b.path)); + const files = Array.from(fileStatMap.entries()).map(([filePath, stat]) => { + insertions += stat.insertions; + deletions += stat.deletions; + return { path: filePath, insertions: stat.insertions, deletions: stat.deletions }; + }); for (const filePath of changedFilesWithoutNumstat) { if (fileStatMap.has(filePath)) continue; From 9188d5f14bb414dd929adf2df0ebf630708eb294 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Sat, 31 Oct 2026 22:30:11 +0000 Subject: [PATCH 2/2] test(server): drop the sort-count test that existing status tests already cover Co-Authored-By: Claude Opus 5.5 --- apps/server/src/vcs/GitVcsDriverCore.test.ts | 52 -------------------- 1 file changed, 52 deletions(-) diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts index 5834100354572..eef44e9c02c80 100644 --- a/apps/server/src/vcs/GitVcsDriverCore.test.ts +++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts @@ -4,7 +4,6 @@ import * as NodeServices from "@effect/platform-node/NodeServices"; import * as HostProcess from "@t3tools/shared/HostProcess"; import { writeFakeCli } from "@t3tools/provider-testing/fakeCli"; import { assert, it, describe } from "@effect/vitest"; -import { vi } from "vite-plus/test"; import * as Deferred from "effect/Deferred"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; @@ -3360,57 +3359,6 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => { }), ); - it.effect("sorts changed files once after adding files without numstat", () => - Effect.gen(function* () { - const cwd = yield* makeTmpDir(); - yield* initRepoWithCommit(cwd); - yield* writeTextFile(cwd, "d.txt", "one\n"); - yield* writeTextFile(cwd, "c.bin", "binary\0one"); - yield* writeTextFile(cwd, "b.txt", "one\n"); - yield* git(cwd, ["add", "."]); - yield* git(cwd, ["commit", "-m", "add files"]); - yield* writeTextFile(cwd, "d.txt", "two\n"); - yield* writeTextFile(cwd, "c.bin", "binary\0two"); - yield* writeTextFile(cwd, "b.txt", "one\ntwo\n"); - yield* writeTextFile(cwd, "e-new.txt", "new\n"); - yield* writeTextFile(cwd, "a-new.txt", "new\n"); - const driver = yield* GitVcsDriver.GitVcsDriver; - const sorts = [vi.spyOn(Array.prototype, "sort"), vi.spyOn(Array.prototype, "toSorted")]; - const sortedLists: Array> = []; - - const status = yield* driver.statusDetailsLocal(cwd).pipe( - Effect.ensuring( - Effect.sync(() => { - for (const sort of sorts) { - // Read the recorded receivers first: mockRestore clears them. - sortedLists.push(...sort.mock.contexts.filter((list) => Array.isArray(list))); - sort.mockRestore(); - } - }), - ), - ); - - assert.deepEqual(status.workingTree.files, [ - { path: "a-new.txt", insertions: 0, deletions: 0 }, - { path: "b.txt", insertions: 1, deletions: 0 }, - { path: "c.bin", insertions: 0, deletions: 0 }, - { path: "d.txt", insertions: 1, deletions: 1 }, - { path: "e-new.txt", insertions: 0, deletions: 0 }, - ]); - assert.equal(status.workingTree.insertions, 2); - assert.equal(status.workingTree.deletions, 1); - // Every array sorted while reading status that holds a returned file entry. - const statusFiles = new Set(status.workingTree.files); - const fileListSorts = sortedLists.filter((list) => - list.some((file) => statusFiles.has(file)), - ); - assert.deepEqual( - fileListSorts.map((list) => list.length), - [status.workingTree.files.length], - ); - }), - ); - it.effect("commits selected files from a nested project directory", () => Effect.gen(function* () { const path = yield* Path.Path;