Skip to content
TypeScript

perf(server): checkpoint capture scans the index listing by record instead of by byte (#21329)

Joseph Vidalc6f2b7dbae47
diff --git a/apps/server/src/vcs/GitVcsDriver.test.ts b/apps/server/src/vcs/GitVcsDriver.test.ts
index 0e3d2b5063e..c7a06c3bdc3 100644
--- a/apps/server/src/vcs/GitVcsDriver.test.ts
+++ b/apps/server/src/vcs/GitVcsDriver.test.ts
@@ -682,9 +682,13 @@ it.effect.each(
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
);
-it.effect.each(["normal", "flags", "sparse"] as const)(
- "checkpoint index inspection handles entries beyond the output cap (index=%s)",
- (indexMode) =>
+it.effect.each(
+ (["normal", "flags", "sparse"] as const).flatMap((indexMode) =>
+ [1, 3, 4096].map((chunkSize) => ({ indexMode, chunkSize })),
+ ),
+)(
+ "checkpoint index inspection handles entries beyond the output cap (index=$indexMode, chunk=$chunkSize)",
+ ({ indexMode, chunkSize }) =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
@@ -720,8 +724,8 @@ it.effect.each(["normal", "flags", "sparse"] as const)(
...input,
maxOutputBytes: 8,
onStdoutChunk: (chunk) => {
- for (let i = 0; i < chunk.length; i++)
- input.onStdoutChunk?.(chunk.subarray(i, i + 1));
+ for (let i = 0; i < chunk.length; i += chunkSize)
+ input.onStdoutChunk?.(chunk.subarray(i, i + chunkSize));
},
}
: input,
diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts
index e3249c70882..acbf817462c 100644
--- a/apps/server/src/vcs/GitVcsDriver.ts
+++ b/apps/server/src/vcs/GitVcsDriver.ts
@@ -899,7 +899,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
let specialFlags = false;
let recordStart = true;
let skipped = false;
- let skippedRecord: number[] = [];
+ let skippedRecord: Uint8Array[] = [];
const skippedPaths: string[] = [];
yield* vcsProcess.run({
operation,
@@ -909,27 +909,35 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
env: commitEnv,
maxOutputBytes: 4_096,
outputMode: "truncate",
+ // Only tags and sparse skip-worktree paths matter; scan NUL-delimited records.
onStdoutChunk: (chunk) => {
- for (const byte of chunk) {
- if (recordStart) skipped = byte === 83;
+ let start = 0;
+ while (start < chunk.length) {
+ const end = chunk.indexOf(0, start);
+ if (recordStart) {
+ const tag = chunk[start]!;
+ skipped = tag === 83;
+ if ((tag >= 97 && tag <= 122) || (!sparseCheckout && tag === 83)) {
+ specialFlags = true;
+ }
+ }
if (skipped && sparseCheckout) {
- if (byte !== 0) skippedRecord.push(byte);
- else {
- if (skippedRecord.at(-1) !== 47) {
- const name = Buffer.from(skippedRecord).subarray(2);
+ skippedRecord.push(
+ Buffer.from(chunk.subarray(start, end === -1 ? undefined : end)),
+ );
+ if (end !== -1) {
+ const record = Buffer.concat(skippedRecord);
+ if (record.at(-1) !== 47) {
+ const name = record.subarray(2);
if (!NodeBuffer.isUtf8(name)) specialFlags = true;
else skippedPaths.push(name.toString("utf8"));
}
skippedRecord = [];
}
}
- if (
- recordStart &&
- ((byte >= 97 && byte <= 122) || (!sparseCheckout && byte === 83))
- ) {
- specialFlags = true;
- }
- recordStart = byte === 0;
+ recordStart = end !== -1;
+ if (!recordStart) break;
+ start = end + 1;
}
},
});