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.
This commit is contained in:
kaitranntt
2026-02-03 23:57:55 -05:00
parent 57f7a70d67
commit ec4e1ae31c
+4 -5
View File
@@ -642,11 +642,10 @@ export function saveUnifiedConfig(config: UnifiedConfig): void {
lockAcquired = true; lockAcquired = true;
break; break;
} }
// Wait before retry // Synchronous sleep without CPU-intensive busy-wait
const start = Date.now(); // Uses Atomics.wait which properly sleeps the thread
while (Date.now() - start < retryDelayMs) { // Note: saveUnifiedConfig is sync API with 19+ callers, converting to async not feasible
// Busy wait Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, retryDelayMs);
}
} }
if (!lockAcquired) { if (!lockAcquired) {