Skip to content

Replace busy-wait spin loop with Atomics.wait() in fileLock.ts#5

Merged
seabearDEV merged 2 commits intoclaude/verify-codexcli-readme-qVZ44from
copilot/sub-pr-2-another-one
Feb 21, 2026
Merged

Replace busy-wait spin loop with Atomics.wait() in fileLock.ts#5
seabearDEV merged 2 commits intoclaude/verify-codexcli-readme-qVZ44from
copilot/sub-pr-2-another-one

Conversation

Copy link
Contributor

Copilot AI commented Feb 21, 2026

acquireLock used a spin loop (while (Date.now() - start < waitMs)) for exponential backoff between retries, burning CPU under any lock contention.

Changes

  • src/utils/fileLock.ts: Replace spin loop with Atomics.wait(), which suspends the thread for the target duration at the OS level with zero CPU burn
  • Allocate the required SharedArrayBuffer/Int32Array once at module level (_sleepBuf) rather than on every retry
// Before
const start = Date.now();
while (Date.now() - start < waitMs) { /* spin */ }

// After
Atomics.wait(_sleepBuf, 0, 0, waitMs);

The function stays synchronous — no async propagation needed — since Atomics.wait() is a blocking call.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: seabearDEV <40605056+seabearDEV@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on verify codexcli readme Replace busy-wait spin loop with Atomics.wait() in fileLock.ts Feb 21, 2026
Copilot AI requested a review from seabearDEV February 21, 2026 20:26
@seabearDEV seabearDEV marked this pull request as ready for review February 21, 2026 20:33
Copilot AI review requested due to automatic review settings February 21, 2026 20:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR attempts to replace a CPU-intensive busy-wait spin loop with Atomics.wait() for better CPU efficiency during lock acquisition retries. However, the implementation has a critical flaw that prevents it from working.

Changes:

  • Modified src/utils/fileLock.ts to use Atomics.wait() with a shared buffer instead of busy-wait loop
  • Extensive modifications to package-lock.json removing/adding "peer": true flags on various dependencies

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/utils/fileLock.ts Replaces busy-wait loop with Atomics.wait() for sleep during lock retry backoff
package-lock.json Modifies peer dependency flags across numerous ESLint and dev packages (appears unrelated to PR purpose)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@seabearDEV seabearDEV merged commit ee15132 into claude/verify-codexcli-readme-qVZ44 Feb 21, 2026
6 checks passed
@seabearDEV seabearDEV deleted the copilot/sub-pr-2-another-one branch February 21, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants