Skip to content

Redesign CLI executor to avoid spin looping when idle#4994

Open
jedel1043 wants to merge 8 commits intoboa-dev:mainfrom
jedel1043:cli-cpu-usage
Open

Redesign CLI executor to avoid spin looping when idle#4994
jedel1043 wants to merge 8 commits intoboa-dev:mainfrom
jedel1043:cli-cpu-usage

Conversation

@jedel1043
Copy link
Member

@jedel1043 jedel1043 commented Mar 11, 2026

The design of our current event loop on the CLI has a couple of warts; one of them being that if there are any async jobs or timeout jobs but not any other type of job on the queue, it will start spin looping, consuming a lot of CPU resources.

This PR completely redesigns our event loop to use smol and cooperative async tasks to push the jobs forward, which avoids spin looping by delegating pauses and timeouts to smol (effectively delegating those to the OS, and OS sleeping = 0% CPU usage). This redesign also modularizes the way jobs are ran; instead of having a big loop that goes through all of the job queues at once, it extracts the running logic of each job queue into independent async tasks

@jedel1043 jedel1043 added the A-Bug Something isn't working label Mar 11, 2026
@jedel1043 jedel1043 requested a review from a team as a code owner March 11, 2026 02:12
@jedel1043 jedel1043 added A-Enhancement New feature or request C-CLI Issues and PRs related to the Boa command line interface. labels Mar 11, 2026
@github-actions
Copy link

github-actions bot commented Mar 11, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 50,073 50,073 0
Ignored 2,072 2,072 0
Failed 818 818 0
Panics 0 0 0
Conformance 94.54% 94.54% 0.00%

Tested main commit: 3f04847b88529e2c62f13d2b36ed4149df507211
Tested PR commit: fbf2312d53205ff810d4f0161f3f30ba22e56117
Compare commits: 3f04847...fbf2312

@codecov
Copy link

codecov bot commented Mar 11, 2026

Codecov Report

❌ Patch coverage is 10.56911% with 110 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.50%. Comparing base (6ddc2b4) to head (5ed2f6d).
⚠️ Report is 894 commits behind head on main.

Files with missing lines Patch % Lines
cli/src/executor.rs 0.00% 88 Missing ⚠️
core/engine/src/job.rs 40.00% 18 Missing ⚠️
cli/src/main.rs 0.00% 2 Missing ⚠️
core/engine/src/builtins/atomics/futex.rs 33.33% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #4994       +/-   ##
===========================================
+ Coverage   47.24%   59.50%   +12.25%     
===========================================
  Files         476      580      +104     
  Lines       46892    63301    +16409     
===========================================
+ Hits        22154    37666    +15512     
- Misses      24738    25635      +897     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jedel1043 jedel1043 closed this Mar 14, 2026
@jedel1043 jedel1043 deleted the cli-cpu-usage branch March 14, 2026 18:58
@jedel1043 jedel1043 restored the cli-cpu-usage branch March 14, 2026 18:58
@jedel1043 jedel1043 reopened this Mar 14, 2026
@jedel1043 jedel1043 added the Waiting On Review Waiting on reviews from the maintainers label Mar 16, 2026
@jedel1043 jedel1043 removed the A-Enhancement New feature or request label Mar 17, 2026
@github-actions github-actions bot added C-Dependencies Pull requests that update a dependency file C-Builtins PRs and Issues related to builtins/intrinsics labels Mar 17, 2026
@jedel1043 jedel1043 linked an issue Mar 18, 2026 that may be closed by this pull request
@github-actions
Copy link

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 50,079 50,079 0
Ignored 2,072 2,072 0
Failed 812 812 0
Panics 0 0 0
Conformance 94.55% 94.55% 0.00%

Tested main commit: c9aaad16b19aa2cadf72838fe8acc1043013023c
Tested PR commit: 5ed2f6d6bcd6e1b2a2e91a60963e3881dab794bc
Compare commits: c9aaad1...5ed2f6d

@jedel1043 jedel1043 requested a review from hansl March 19, 2026 17:16
Comment on lines +158 to +165
#[cfg(debug_assertions)]
{
let callback = self.0.take();
assert!(
callback.is_some(),
"setting a callback on an already used cancellation token"
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this just:

Suggested change
#[cfg(debug_assertions)]
{
let callback = self.0.take();
assert!(
callback.is_some(),
"setting a callback on an already used cancellation token"
);
}
debug_assert!(self.0.take().is_none(), "setting a callback on an already used cancellation token");

Also, I think the logic is wrong, you want to make sure it's None before setting it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah, it needs to check if it is Some, otherwise the token has already been used and the Cell has a None on its place

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Bug Something isn't working C-Builtins PRs and Issues related to builtins/intrinsics C-CLI Issues and PRs related to the Boa command line interface. C-Dependencies Pull requests that update a dependency file Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

boa_cli 100% single-core CPU usage while idling

2 participants