Skip to content

Conversation

anvilvapre
Copy link
Contributor

@anvilvapre anvilvapre commented Jun 17, 2025

See #18491.

Fix for bug where:

  • if now >= nextLogic && renderBeforeNextTick && Renderer.WindowIsSuspended
  • then renderBeforeNextTick will never become false
  • resulting the main loop to end up in a "busy wait"/"spin loop" to wait until now > nextRender
  • causing 60+ execution per millisecond - until nextRender is reached

Changes:

  • If window is suspended: Call Thread.sleep rather than busy wait/spin.
  • Else: also ensure that renderBeforeNextTick will be false - even if there was not time to render - and we skip.

In the rare occasion where !haveSomeTimeUntilNextLogic && !forceRender a render is skipped. This seemed to be the original implied intended behavior. May cause issues if certain logic relies on render ticks to occur. But this also already happens/happened in suspended window mode.

I myself would prefer to update next render time also based on actual time spent rendering. But i guess then you would not be able to meet the indended fps. It would be beneficial on slower systems.

@anvilvapre
Copy link
Contributor Author

Illustration,

Moment where the value of now is the same each main loop iteration - i.e. busy loop, no sleeping till next update.

A-axis is now in millis. Count is the number of times the main loop is called.

image

Zoom in on 2nd spike.

image

@Mailaender Mailaender changed the title Avoid occasional 'busy wait' for next render time in main loop. #18491 Avoid occasional 'busy wait' for next render time in main loop. Jul 15, 2025
@anvilvapre
Copy link
Contributor Author

request to put a next-release tag on this. fine if you reject it, for as long as you considered it.

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.

1 participant