Update increaseticks sleep strategy #2655
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an experiment to improve the accuracy of the engine that is
increaseticks
.PIC_RunQueue
is at the mercy of the 1mssleep_for
, which can cause an entire millisecond tick to be missed. By lowering the sleep time,PIC_RunQueue
can run more often. This allows it to get closer to the precise time specified when an event is added viaPIC_AddEvent
; many calls throughout the codebase provide sub-millisecond or fractional delays.Also, it keeps track of the excess microseconds after each sleep and adjusts
ticksDone
for more accuracy during cycle guessing, sincesleep_for
isn't precise; for example, a 1ms sleep is actually ~1150-1200us on my M1 Mac, causing it to think it slept for a total of 10 ticks when it was really 11.None of this should provide a massive difference, but it should give much more accurate responsiveness within ticks. I did notice a difference on the Future Crew Panic demo, on the first 'scrollers suck' portion, with fewer flickers compared to
main
. At best, it will help smooth out micro-glitches in audio and video here and there, and worst case it should be identical tomain
.The one wild card is the new sleepDuration:
On my M1 Mac, it significantly reduces CPU usage compared to 250 or 500 (and even 1000), but that is completely up to the Host OS scheduler. I wanted to start with an aggressive value, and we can back it off if empirical testing warrants.