Skip to content

fix: Dispatcher - back off with SpinWait while waiting for a batch to finish - #3685

Closed
Kryptos-FR wants to merge 1 commit into
stride3d:masterfrom
Kryptos-FR:fix/dispatcher-spin-wait
Closed

Kryptos-FR wants to merge 1 commit into
stride3d:masterfrom
Kryptos-FR:fix/dispatcher-spin-wait

Conversation

@Kryptos-FR

@Kryptos-FR Kryptos-FR commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

PR Details

When there is no work to steal, the wait loops in Dispatcher.ForBatched and WaitCompletion spun on TryCooperate without any pause. A thread waiting this way (e.g. the editor game thread waiting for a shader compile) burns a full core, and under Wine the runtime can't suspend it for a garbage collection: the GC retries NtSuspendThread forever and the process freezes (seen with the WPF GameStudio scene editor).

Call SpinWait.SpinOnce when TryCooperate finds nothing to do; it spins briefly, then yields and sleeps, so the waiting thread still picks up work promptly.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

When there is no work to steal, the wait loops in Dispatcher.ForBatched and
WaitCompletion spun on TryCooperate without any pause. A thread waiting this way
(e.g. the editor game thread waiting for a shader compile) burns a full core,
and under Wine the runtime can't suspend it for a garbage collection: the GC
retries NtSuspendThread forever and the process freezes (seen with the WPF
GameStudio scene editor).

Call SpinWait.SpinOnce when TryCooperate finds nothing to do; it spins briefly,
then yields and sleeps, so the waiting thread still picks up work promptly.
@Kryptos-FR
Kryptos-FR requested a review from Eideren October 24, 2026 14:52
@Kryptos-FR Kryptos-FR self-assigned this Oct 24, 2026
@Kryptos-FR Kryptos-FR added bug-fix area-Core Issue of the engine unrelated to other defined areas labels Oct 24, 2026
@Kryptos-FR Kryptos-FR changed the title fix: dispatcher - back off with SpinWait while waiting for a batch to finish fix: Dispatcher - back off with SpinWait while waiting for a batch to finish Oct 24, 2026
@Kryptos-FR Kryptos-FR added ci-enduser Run the end-user sample screenshot + packaging suite on this PR ci-editor Run the GameStudio editor screenshot suite on this PR labels Oct 24, 2026
@Eideren

Eideren commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks for adding me into this loop, I believe #3600 is what you're looking for. Have a look at the discussion we had there, your input for the editor side of the issue would be very welcome.

Although yours does take care of Sorts completion as well, so maybe add on top of that PR.

@Kryptos-FR

Copy link
Copy Markdown
Member Author

@Eideren Unfortunately I'm not enough of an expert to understand why the original commit of that PR (which is similar to mine) wasn't a good idea. My limited testing worked with this change but it wasn't heavy load as you mentioned. Or to be more precise, without that change it, the editor wasn't working on Wine. (along with this other fix: #3684).

@Kryptos-FR

Copy link
Copy Markdown
Member Author

Closed in favor of #3600.

@Kryptos-FR Kryptos-FR closed this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Core Issue of the engine unrelated to other defined areas bug-fix ci-editor Run the GameStudio editor screenshot suite on this PR ci-enduser Run the end-user sample screenshot + packaging suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants