fix: budget workers for expensive captures

This commit is contained in:
Miguel Ángel
2026-04-27 22:53:27 -04:00
parent 37827cdaec
commit 36b3fc8cd9
10 changed files with 978 additions and 101 deletions
@@ -1,5 +1,5 @@
import { describe, it, expect } from "vitest";
import { distributeFrames } from "./parallelCoordinator.js";
import { calculateOptimalWorkers, distributeFrames } from "./parallelCoordinator.js";
describe("distributeFrames", () => {
it("distributes frames evenly across workers", () => {
@@ -42,3 +42,29 @@ describe("distributeFrames", () => {
expect(tasks.map((t) => t.workerId)).toEqual([0, 1, 2]);
});
});
describe("calculateOptimalWorkers", () => {
it("lets high-cost auto renders fall back to one worker when CPU budget requires it", () => {
const workers = calculateOptimalWorkers(180, undefined, {
concurrency: 6,
coresPerWorker: 100,
minParallelFrames: 120,
largeRenderThreshold: 1000,
captureCostMultiplier: 4,
});
expect(workers).toBe(1);
});
it("does not apply capture cost to explicit worker requests", () => {
const workers = calculateOptimalWorkers(180, 4, {
concurrency: 6,
coresPerWorker: 100,
minParallelFrames: 120,
largeRenderThreshold: 1000,
captureCostMultiplier: 4,
});
expect(workers).toBe(4);
});
});