An open source design system that's fully customizable and agent ready
TypeScript
test(Markdown): spin the FR23 clock check's worker for CPU time, not wall time (#9944)
Christopher Chedeauc1a7ff7f05b3
diff --git a/packages/core/src/Markdown/Markdown.fr23.perf.test.ts b/packages/core/src/Markdown/Markdown.fr23.perf.test.tsindex 6cb0599c12..6da111e0a3 100644--- a/packages/core/src/Markdown/Markdown.fr23.perf.test.ts+++ b/packages/core/src/Markdown/Markdown.fr23.perf.test.ts@@ -278,15 +278,21 @@ describe('Markdown FR23 helper overhead', () => {});it("times only the main thread, not V8's or a worker's background threads", async () => {- // A worker spins for 300 ms of CPU while this thread sleeps without any.- // The process clock counts the worker's time; the sampling clock must not.+ // A worker spins until its own thread has used 300 ms of CPU, while this+ // thread sleeps without any. The spin counts CPU time, not wall time, so+ // a busy machine cannot shorten it. The process clock counts the worker's+ // time; the sampling clock must not.const flag = new Int32Array(new SharedArrayBuffer(4));const processBefore = process.cpuUsage();const threadBefore = mainThreadCpuTime();const worker = new Worker(`const {workerData} = require('node:worker_threads');- const end = Date.now() + 300;- while (Date.now() < end) {}+ const start = process.threadCpuUsage();+ const used = () => {+ const usage = process.threadCpuUsage(start);+ return usage.user + usage.system;+ };+ while (used() < 300_000) {}Atomics.store(workerData, 0, 1);Atomics.notify(workerData, 0);`,{eval: true, workerData: flag},