Skip to content

Commit 264e9f9

Browse files
committed
perf(server): stop measuring replay bytes once over budget
threadReplayEncodedBytes stringified every replay item even after crossing the 1MiB resume cap. Break early once over the limit. Totals under the cap stay exact, over-cap stays over-cap so resume still picks a snapshot.
1 parent da8cc59 commit 264e9f9

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)