mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 14:16:43 +00:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user