Skip to content

Replace busy-wait with sleep_for in StorageAttachmentGuard::Wait#240

Merged
anasdorbani merged 2 commits intodevfrom
copilot/sub-pr-239
Mar 2, 2026
Merged

Replace busy-wait with sleep_for in StorageAttachmentGuard::Wait#240
anasdorbani merged 2 commits intodevfrom
copilot/sub-pr-239

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

StorageAttachmentGuard::Wait was implemented as a spin loop, burning a full CPU core for up to 10 seconds (10 retries × 1000ms) during storage attachment retries.

Changes

  • src/core/config/config.cpp: Replace busy-wait spin loop with std::this_thread::sleep_for, and add #include <thread>
// Before
void Config::StorageAttachmentGuard::Wait(int milliseconds) {
    auto start = std::chrono::steady_clock::now();
    auto duration = std::chrono::milliseconds(milliseconds);
    while (std::chrono::steady_clock::now() - start < duration) {
        // Busy-wait until the specified duration has elapsed
    }
}

// After
void Config::StorageAttachmentGuard::Wait(int milliseconds) {
    std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ntGuard::Wait

Co-authored-by: anasdorbani <95044293+anasdorbani@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on WASM support implementation Replace busy-wait with sleep_for in StorageAttachmentGuard::Wait Mar 2, 2026
@anasdorbani anasdorbani marked this pull request as ready for review March 2, 2026 19:59
Copilot AI review requested due to automatic review settings March 2, 2026 19:59
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

Replace CPU-burning busy-wait in Config::StorageAttachmentGuard::Wait with std::this_thread::sleep_for during storage attachment retries.

Changes:

  • Replace spin loop with std::this_thread::sleep_for(std::chrono::milliseconds(...))
  • Add #include <thread> to support sleep_for
  • Add _codeql_detected_source_root file

Reviewed changes

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

File Description
src/core/config/config.cpp Replaces busy-wait loop with sleep_for to avoid pegging a CPU core during retry waits.
_codeql_detected_source_root Adds a CodeQL source-root marker file to the repository.
Comments suppressed due to low confidence (3)

src/core/config/config.cpp:149

  • This file contains duplicated implementations of Config::StorageAttachmentGuard::Wait (and nearby methods in the same regions). Even if these are under different compile-time branches, keeping two copies increases the risk of future drift. Consider factoring the shared logic into a single helper (or a single implementation selected via #if/#else around only the differing parts) so changes only need to be made once.
void Config::StorageAttachmentGuard::Wait(int milliseconds) {
    std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
}

src/core/config/config.cpp:202

  • This file contains duplicated implementations of Config::StorageAttachmentGuard::Wait (and nearby methods in the same regions). Even if these are under different compile-time branches, keeping two copies increases the risk of future drift. Consider factoring the shared logic into a single helper (or a single implementation selected via #if/#else around only the differing parts) so changes only need to be made once.
void Config::StorageAttachmentGuard::Wait(int milliseconds) {
    std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
}

_codeql_detected_source_root:1

  • _codeql_detected_source_root looks like a generated/tooling artifact (single-dot marker). If it’s produced by CodeQL or CI tooling, it generally shouldn’t be committed; prefer configuring CodeQL to detect the root via workflow settings, or add this file to .gitignore and remove it from the PR to avoid persistent noise in future diffs.

@anasdorbani anasdorbani merged commit 91f6cc8 into dev Mar 2, 2026
3 of 4 checks passed
@anasdorbani anasdorbani deleted the copilot/sub-pr-239 branch March 2, 2026 20:01
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