Skip to content

Commit c6f2b7d

Browse files
perf(server): checkpoint capture scans the index listing by record instead of by byte (pingdotgg#21329)
Co-authored-by: maria-rcks <[email protected]>
1 parent 0ed5540 commit c6f2b7d

2 files changed

Lines changed: 31 additions & 19 deletions

File tree

‎apps/server/src/vcs/GitVcsDriver.test.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,13 @@ it.effect.each(
682682
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
683683
);
684684

685-
it.effect.each(["normal", "flags", "sparse"] as const)(
686-
"checkpoint index inspection handles entries beyond the output cap (index=%s)",
687-
(indexMode) =>
685+
it.effect.each(
686+
(["normal", "flags", "sparse"] as const).flatMap((indexMode) =>
687+
[1, 3, 4096].map((chunkSize) => ({ indexMode, chunkSize })),
688+
),
689+
)(
690+
"checkpoint index inspection handles entries beyond the output cap (index=$indexMode, chunk=$chunkSize)",
691+
({ indexMode, chunkSize }) =>
688692
Effect.gen(function* () {
689693
const fs = yield* FileSystem.FileSystem;
690694
const path = yield* Path.Path;
@@ -720,8 +724,8 @@ it.effect.each(["normal", "flags", "sparse"] as const)(
720724
...input,
721725
maxOutputBytes: 8,
722726
onStdoutChunk: (chunk) => {
723-
for (let i = 0; i < chunk.length; i++)
724-
input.onStdoutChunk?.(chunk.subarray(i, i + 1));
727+
for (let i = 0; i < chunk.length; i += chunkSize)
728+
input.onStdoutChunk?.(chunk.subarray(i, i + chunkSize));
725729
},
726730
}
727731
: input,

‎apps/server/src/vcs/GitVcsDriver.ts‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
899899
let specialFlags = false;
900900
let recordStart = true;
901901
let skipped = false;
902-
let skippedRecord: number[] = [];
902+
let skippedRecord: Uint8Array[] = [];
903903
const skippedPaths: string[] = [];
904904
yield* vcsProcess.run({
905905
operation,
@@ -909,27 +909,35 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
909909
env: commitEnv,
910910
maxOutputBytes: 4_096,
911911
outputMode: "truncate",
912+
// Only tags and sparse skip-worktree paths matter; scan NUL-delimited records.
912913
onStdoutChunk: (chunk) => {
913-
for (const byte of chunk) {
914-
if (recordStart) skipped = byte === 83;
914+
let start = 0;
915+
while (start < chunk.length) {
916+
const end = chunk.indexOf(0, start);
917+
if (recordStart) {
918+
const tag = chunk[start]!;
919+
skipped = tag === 83;
920+
if ((tag >= 97 && tag <= 122) || (!sparseCheckout && tag === 83)) {
921+
specialFlags = true;
922+
}
923+
}
915924
if (skipped && sparseCheckout) {
916-
if (byte !== 0) skippedRecord.push(byte);
917-
else {
918-
if (skippedRecord.at(-1) !== 47) {
919-
const name = Buffer.from(skippedRecord).subarray(2);
925+
skippedRecord.push(
926+
Buffer.from(chunk.subarray(start, end === -1 ? undefined : end)),
927+
);
928+
if (end !== -1) {
929+
const record = Buffer.concat(skippedRecord);
930+
if (record.at(-1) !== 47) {
931+
const name = record.subarray(2);
920932
if (!NodeBuffer.isUtf8(name)) specialFlags = true;
921933
else skippedPaths.push(name.toString("utf8"));
922934
}
923935
skippedRecord = [];
924936
}
925937
}
926-
if (
927-
recordStart &&
928-
((byte >= 97 && byte <= 122) || (!sparseCheckout && byte === 83))
929-
) {
930-
specialFlags = true;
931-
}
932-
recordStart = byte === 0;
938+
recordStart = end !== -1;
939+
if (!recordStart) break;
940+
start = end + 1;
933941
}
934942
},
935943
});

0 commit comments

Comments
 (0)