From ec4e1ae31c882e8422e8defca6c10a9c79addc5d Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Tue, 3 Feb 2026 23:57:55 -0500 Subject: [PATCH] perf(config): replace busy-wait with Atomics.wait in lock retry Use Atomics.wait for synchronous sleep instead of CPU-intensive busy-wait loop. This properly sleeps the thread without wasting cycles. Addresses code review feedback on PR #441. --- src/config/unified-config-loader.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/config/unified-config-loader.ts b/src/config/unified-config-loader.ts index 1bb0e3c2..a8e336de 100644 --- a/src/config/unified-config-loader.ts +++ b/src/config/unified-config-loader.ts @@ -642,11 +642,10 @@ export function saveUnifiedConfig(config: UnifiedConfig): void { lockAcquired = true; break; } - // Wait before retry - const start = Date.now(); - while (Date.now() - start < retryDelayMs) { - // Busy wait - } + // Synchronous sleep without CPU-intensive busy-wait + // Uses Atomics.wait which properly sleeps the thread + // Note: saveUnifiedConfig is sync API with 19+ callers, converting to async not feasible + Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, retryDelayMs); } if (!lockAcquired) {