Open source CapCut alternative.
TypeScript
fix(site): the memory ceiling is a quarter of what a browser reports
David Lefcc54b552d5c
diff --git a/site/src/cut/lib/frameSource.test.ts b/site/src/cut/lib/frameSource.test.tsindex 4ebb5c8c..9c33ee29 100644--- a/site/src/cut/lib/frameSource.test.ts+++ b/site/src/cut/lib/frameSource.test.ts@@ -363,10 +363,10 @@ describe("walkClaim", () => {describe("FrameSourcePool", () => {// The pool's budgets are the smaller of what it was tuned to want and this// machine's share, and these tests are about the tuning: they put the pool- // on a machine with room, which is what a sixteen-gigabyte report is, and- // hand the machine back after.+ // on a machine with room, which is the most a browser will report, and hand+ // the machine back after.beforeEach(() => {- Object.defineProperty(navigator, "deviceMemory", { value: 16, configurable: true });+ Object.defineProperty(navigator, "deviceMemory", { value: 8, configurable: true });});afterEach(() => {delete (navigator as { deviceMemory?: number }).deviceMemory;diff --git a/site/src/cut/lib/memoryBudget.test.ts b/site/src/cut/lib/memoryBudget.test.tsindex 259e87ce..cf902e93 100644--- a/site/src/cut/lib/memoryBudget.test.ts+++ b/site/src/cut/lib/memoryBudget.test.ts@@ -30,8 +30,8 @@ describe("the ceiling", () => {test("is a share of the machine", () => {// The environment the tests run in reports no `deviceMemory`, which is the// same silence Safari and Firefox give a real page: the assumed size- // stands in, and an eighth of it is the tab's.- expect(memoryCeiling()).toBe(2 ** 30);+ // stands in, and a quarter of it is the tab's.+ expect(memoryCeiling()).toBe(2 * 2 ** 30);expect(memoryCeiling()).toBe(memoryCeiling());});diff --git a/site/src/cut/lib/memoryBudget.ts b/site/src/cut/lib/memoryBudget.tsindex de61dcab..72669a54 100644--- a/site/src/cut/lib/memoryBudget.ts+++ b/site/src/cut/lib/memoryBudget.ts@@ -67,20 +67,26 @@ const SHARES: Record<MemoryBucket, number> = {* The ceiling covers the tab and the decoder process working for it, which* between them are one of several things the machine is running: the* operating system, the browser's other processes, the person's other tabs.- * An eighth of what the browser reports leaves those the rest. Past that the+ * A quarter of what the browser reports leaves those the rest. Past that the* machine starts swapping, and a swapping machine previews worse than one* decoding at half the size — the picture stops for a page fault, which no- * amount of decode headroom recovers. An 18GB laptop reports sixteen and- * gets two gigabytes, which is where the tuned sizes below start to bind.+ * amount of decode headroom recovers.+ *+ * The number the browser reports is capped at eight, so eight is the largest+ * ceiling this can be a quarter of: two gigabytes, which is the figure the+ * sizes below are tuned against. Taking a smaller fraction would mean no+ * machine ever runs at those sizes, since none can report more.*/-const CEILING_SHARE = 0.125;+const CEILING_SHARE = 0.25;/*** What to assume when the browser does not say.** `deviceMemory` is Chrome and Edge only; Safari and Firefox report nothing.- * Chrome rounds to a power of two and reports sixteen on the machines that- * have it, so eight is the figure for a machine of ordinary size — assuming- * it for the browsers that stay silent puts them on that footing.+ * What it reports is rounded down to a power of two and capped at eight, so+ * eight already means "eight or more" — a laptop with that much and a+ * workstation with sixty-four say the same thing. Assuming it for the+ * browsers that stay silent puts them on the same footing as the machines we+ * can see, which are overwhelmingly the same machines.*/const ASSUMED_GB = 8;/** The smallest ceiling worth honouring: below this the editor cannot hold a@@ -93,10 +99,11 @@ const GB = 2 ** 30;/*** Bytes the editor may hold.*- * `deviceMemory` is coarse by design — it rounds to a power of two — which is- * enough to tell the machines that need protecting from the machines that do- * not, and it is the only figure a page is given. It is read each time it is- * asked for: the figure never moves, and the read is a property lookup.+ * `deviceMemory` is coarse by design — it rounds to a power of two and caps at+ * eight — which is enough to tell the machines that need protecting from the+ * machines that do not, and it is the only figure a page is given. It is read+ * each time it is asked for: the figure never moves, and the read is a+ * property lookup.*/export function memoryCeiling(): number {const reported =diff --git a/site/src/cut/lib/stickerCache.test.ts b/site/src/cut/lib/stickerCache.test.tsindex 0e97a9ce..6826bef5 100644--- a/site/src/cut/lib/stickerCache.test.ts+++ b/site/src/cut/lib/stickerCache.test.ts@@ -3,9 +3,9 @@ import { setRasterFactory } from "./raster";import { cutRenderEnv } from "./textRender";import type { MediaAsset } from "./types";-// A sticker this big costs four megabytes decoded, so two of them fill the-// share the stickers hold at the test ceiling and a third pushes one out.-const SIDE = 1000;+// A sticker this big costs about seven megabytes decoded, so two of them fill+// the share the stickers hold at the test ceiling and a third pushes one out.+const SIDE = 1300;let decodes = 0;setRasterFactory({