Skip to content

Commit a2a1f2b

Browse files
perf(server): stop measuring replay bytes once over budget (pingdotgg#27405)
1 parent bd90732 commit a2a1f2b

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎apps/server/src/orchestration-v2/ThreadStream.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ export function isThreadReplayRawPayloadSafe(rawPayloadBytes: number): boolean {
2626
return rawPayloadBytes <= THREAD_RESUME_MAX_RAW_PAYLOAD_BYTES;
2727
}
2828

29-
export function threadReplayEncodedBytes(items: ReadonlyArray<unknown>): number {
29+
export function threadReplayEncodedBytes(
30+
items: ReadonlyArray<unknown>,
31+
limit: number = THREAD_RESUME_MAX_REPLAY_ENCODED_BYTES,
32+
): number {
3033
let total = 0;
3134
for (const item of items) {
3235
const encoded = JSON.stringify(item);
3336
total += Buffer.byteLength(encoded ?? "", "utf8");
37+
if (total > limit) break;
3438
}
3539
return total;
3640
}

0 commit comments

Comments
 (0)