XAsync pool: idle workers end, bursts stop at a cap, delayed callbacks share one timer thread (rest of #228) #466

Open
illuminatedfellow wants to merge 2 commits from upstream-pr/466 into main
illuminatedfellow commented 2026-11-27 13:40:35 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by illuminatedfellow on 2026-11-27T13:40:35Z.


Part of #228 (item 3). Stacked on #244: this branch is #244's commit plus one more, so review the last commit, or wait for #244 to merge and the diff here shrinks to it.

What changes, in crates/victory-hle/src/modules/xasync.rs:

  • 3.1, idle workers never exit: a pool worker that waits 30 s with nothing to do now ends.
  • 3.2, a thread per delayed callback: delayed callbacks (XTaskQueueSubmitDelayedCallback, XAsyncSchedule with a delay) now wait on one timer thread and are delivered on the pool, instead of each starting a thread that sleeps out its delay.
  • 3.3, bursts start about one worker per task: the pool starts workers up to twice the core count (at least 4). Past that, tasks wait for a worker, unless no worker has taken a task for 50 ms. Then the workers may all be blocked on callbacks still queued, so the pool starts one more, and checks again 50 ms later. This is option (a) from #228, the soft cap with a starvation escape. The go-ahead there didn't pick between (a) and (b); I went with (a) because a callback that waits on another still never starves. If you'd rather have (b), the hard cap with a logged warning, say so and I'll switch it.

Termination still takes a queue's callbacks back out of the pool and cancels them: the pool keeps titles' callbacks apart from its own jobs.

Tests added:

  • idle_pool_workers_end
  • a_burst_starts_no_more_workers_than_the_cap
  • a_stalled_pool_grows_past_its_cap
  • delayed_callbacks_do_not_start_a_thread_each: fails on #244 alone (200 threads for 200 delayed callbacks), passes here.

Tested on Linux with xasync.rs built alone with a stub for xgameruntime, since victory-hle needs Windows to build: all 20 xasync tests pass, 60 runs in release, 20 in debug and 15 under CPU load without a failure; clippy --all-targets -D warnings is clean on Rust 1.97. Not built with the pinned 1.98.1 or on Windows; CI here will be the first run of that.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:5527609469 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/466). Originally posted by [illuminatedfellow](https://github.com/illuminatedfellow) on 2026-11-27T13:40:35Z. --- Part of #228 (item 3). Stacked on #244: this branch is #244's commit plus one more, so review the last commit, or wait for #244 to merge and the diff here shrinks to it. What changes, in `crates/victory-hle/src/modules/xasync.rs`: - **3.1, idle workers never exit:** a pool worker that waits 30 s with nothing to do now ends. - **3.2, a thread per delayed callback:** delayed callbacks (`XTaskQueueSubmitDelayedCallback`, `XAsyncSchedule` with a delay) now wait on one timer thread and are delivered on the pool, instead of each starting a thread that sleeps out its delay. - **3.3, bursts start about one worker per task:** the pool starts workers up to twice the core count (at least 4). Past that, tasks wait for a worker, unless no worker has taken a task for 50 ms. Then the workers may all be blocked on callbacks still queued, so the pool starts one more, and checks again 50 ms later. This is option (a) from #228, the soft cap with a starvation escape. The go-ahead there didn't pick between (a) and (b); I went with (a) because a callback that waits on another still never starves. If you'd rather have (b), the hard cap with a logged warning, say so and I'll switch it. Termination still takes a queue's callbacks back out of the pool and cancels them: the pool keeps titles' callbacks apart from its own jobs. Tests added: - `idle_pool_workers_end` - `a_burst_starts_no_more_workers_than_the_cap` - `a_stalled_pool_grows_past_its_cap` - `delayed_callbacks_do_not_start_a_thread_each`: fails on #244 alone (200 threads for 200 delayed callbacks), passes here. Tested on Linux with `xasync.rs` built alone with a stub for `xgameruntime`, since `victory-hle` needs Windows to build: all 20 xasync tests pass, 60 runs in release, 20 in debug and 15 under CPU load without a failure; `clippy --all-targets -D warnings` is clean on Rust 1.97. Not built with the pinned 1.98.1 or on Windows; CI here will be the first run of that.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/466:upstream-pr/466'
git switch 'upstream-pr/466'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/466'
git switch 'upstream-pr/466'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/466'
git switch 'upstream-pr/466'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/466'
git switch 'main'
git merge --squash 'upstream-pr/466'
git switch 'main'
git merge --ff-only 'upstream-pr/466'
git switch 'main'
git merge 'upstream-pr/466'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
avatarmanz/VIctory-7900XTX!466
No description provided.