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;
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) {