Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

perf(web): commit a desktop recording source in 45 s step batches instead of 15 s

Richie McIlroy76190b67920a
diff --git a/apps/web/__tests__/fixtures/source-commit-timings.json b/apps/web/__tests__/fixtures/source-commit-timings.json
index 7828fdb9b..ef2959e3d 100644
--- a/apps/web/__tests__/fixtures/source-commit-timings.json
+++ b/apps/web/__tests__/fixtures/source-commit-timings.json
@@ -3,7 +3,7 @@
"name": "long-s3",
"terminalResult": "ready",
"baselineWallMs": 919500,
- "expectedBatchedSteps": 31,
+ "expectedBatchedSteps": 11,
"pageDurationsMs": [
464, 462, 512, 404, 577, 373, 517, 384, 672, 368, 458, 340, 592, 372, 516,
422, 841, 477, 559, 358, 600, 423, 508, 369, 621, 353, 449, 384, 546, 694,
@@ -47,14 +47,14 @@
"name": "short-drive-first",
"terminalResult": "ready",
"baselineWallMs": 29925,
- "expectedBatchedSteps": 2,
+ "expectedBatchedSteps": 1,
"pageDurationsMs": [4693, 2796, 10156, 1521, 8332]
},
{
"name": "short-drive-retry",
"terminalResult": "ready",
"baselineWallMs": 26610,
- "expectedBatchedSteps": 2,
+ "expectedBatchedSteps": 1,
"pageDurationsMs": [4867, 2914, 8932, 2810, 4612]
},
{
diff --git a/apps/web/__tests__/unit/finalize-desktop-recording.test.ts b/apps/web/__tests__/unit/finalize-desktop-recording.test.ts
index dcebcc4ae..e7c420167 100644
--- a/apps/web/__tests__/unit/finalize-desktop-recording.test.ts
+++ b/apps/web/__tests__/unit/finalize-desktop-recording.test.ts
@@ -573,11 +573,13 @@ describe("bounded source commitment steps", () => {
});
it.each([
- [0, 32],
- [-1, 32],
- [1_000, 15],
- [14_999, 2],
- [15_000, 1],
+ [0, 128],
+ [-1, 128],
+ [1_000, 45],
+ [14_999, 4],
+ [15_000, 3],
+ [44_999, 2],
+ [45_000, 1],
[180_000, 1],
])("yields after bounded work with %i ms pages", async (duration, pages) => {
mocks.commitSource.mockImplementation(async (_video, checkpoint) => {
@@ -708,7 +710,7 @@ describe("bounded source commitment steps", () => {
it("leaves dispatch to its own step after a slow commit", async () => {
withCurrent({ source: null });
mocks.commitSource.mockImplementation(async () => {
- vi.setSystemTime(Date.now() + 15_000);
+ vi.setSystemTime(Date.now() + 45_000);
return { source };
});
await expect(
@@ -720,7 +722,7 @@ describe("bounded source commitment steps", () => {
it("does not dispatch while the source commit is still in progress", async () => {
withCurrent({ source: null });
mocks.commitSource.mockImplementation(async (_video, checkpoint) => {
- vi.setSystemTime(Date.now() + 15_000);
+ vi.setSystemTime(Date.now() + 45_000);
return advanceCheckpoint(_video, checkpoint);
});
await expect(
@@ -733,7 +735,7 @@ describe("bounded source commitment steps", () => {
mocks.commitSource.mockImplementation(advanceCheckpoint);
mocks.saveCheckpoint.mockImplementation(async (_attempt, checkpoint) => {
withCurrent({ output: checkpoint });
- vi.setSystemTime(Date.now() + 15_000);
+ vi.setSystemTime(Date.now() + 45_000);
return true;
});
expect(await commitDesktopRecordingAttempt(fixture)).toBe("progress");
diff --git a/apps/web/workflows/finalize-desktop-recording.ts b/apps/web/workflows/finalize-desktop-recording.ts
index cc8323318..1cf017d7d 100644
--- a/apps/web/workflows/finalize-desktop-recording.ts
+++ b/apps/web/workflows/finalize-desktop-recording.ts
@@ -87,8 +87,10 @@ const MULTIPART_OUTPUT_PART_SIZE_BYTES = 64 * 1024 * 1024;
// A remux is about as large as its source, so a source that fits in one part is
// uploaded with one PUT instead of sign-part + PUT + complete round trips.
const SINGLE_PUT_OUTPUT_MAX_SOURCE_BYTES = MULTIPART_OUTPUT_PART_SIZE_BYTES;
-const SOURCE_COMMIT_BATCH_MAX_CHECKPOINTS = 32;
-const SOURCE_COMMIT_BATCH_DURATION_MS = 15_000;
+const SOURCE_COMMIT_BATCH_MAX_CHECKPOINTS = 128;
+// A page can still run for its 180 s timeout after this budget is spent, so a step stays far inside
+// the function's max duration while a long commit needs a third of the step hops it did at 15 s.
+const SOURCE_COMMIT_BATCH_DURATION_MS = 45_000;
const TRANSCRIPTION_QUEUE_MAX_ATTEMPTS = 12;
function getErrorMessage(error: unknown) {