love.timer.sleep resolution test

General discussion about LÖVE, Lua, game development, puns, and unicorns.
grump
Party member
Posts: 813
Joined: Sat Jul 22, 2017 7:43 pm

Re: love.timer.sleep resolution test

Post by grump »

slime wrote: Tue Sep 28, 2021 12:55 pm If you have a suggestion that's more robust while providing similar benefits I'm interested
An obvious way to allow easier control would be a love.conf setting for the sleep duration.

If that's no good then maybe there should be no sleeping when vsync is enabled. It's taking away time for no good reason. Vsync may be disabled in the driver settings, but if that's what the user want then so be it.
User avatar
slime
Solid Snayke
Posts: 2954
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.timer.sleep resolution test

Post by slime »

grump wrote: Tue Sep 28, 2021 8:05 pm An obvious way to allow easier control would be a love.conf setting for the sleep duration.
What would you set in love.conf other than 0 or 1/1000? I suppose you just mean a toggle rather than specifying the duration?
grump wrote: Tue Sep 28, 2021 8:05 pm If that's no good then maybe there should be no sleeping when vsync is enabled. It's taking away time for no good reason. Vsync may be disabled in the driver settings, but if that's what the user want then so be it.
vsync will often busy-wait (depending on the graphics driver), which burns CPU time. So the sleep is still useful when vsync is enabled.

One of the reasons why I haven't rushed to take the sleep out or make an easy toggle for it in the past is because there are numerous situations like that where it might seem redundant to people unfamiliar with the myriad of systems out there, even though it still ends up being useful in practice.

Removing the sleep is probably one of the last optimizations someone should do (if a game truly still needs optimizing at that point), since unlike typical CPU performance optimizations, there are a many downsides to taking that 1ms in games that aren't performance-starved.
User avatar
pgimeno
Party member
Posts: 2818
Joined: Sun Oct 18, 2015 2:58 pm

Re: love.timer.sleep resolution test

Post by pgimeno »

slime wrote: Tue Sep 28, 2021 9:32 pm vsync will often busy-wait (depending on the graphics driver), which burns CPU time. So the sleep is still useful when vsync is enabled.
Is it really a significant advantage to wait for 1 ms and do a busy wait for 15.666 ms?

Anyway, that sleep doesn't really bother me. If I have to remove it (hasn't been the case so far), I can just monkey-patch love.timer.sleep.
User avatar
slime
Solid Snayke
Posts: 2954
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.timer.sleep resolution test

Post by slime »

pgimeno wrote: Tue Sep 28, 2021 10:26 pm Is it really a significant advantage to wait for 1 ms and do a busy wait for 15.666 ms?

Anyway, that sleep doesn't really bother me. If I have to remove it (hasn't been the case so far), I can just monkey-patch love.timer.sleep.
Yes.

Personally I'd recommend customizing love.run rather than monkeypatching, mostly because the latter tends to make code less predictable in general.
User avatar
pgimeno
Party member
Posts: 2818
Joined: Sun Oct 18, 2015 2:58 pm

Re: love.timer.sleep resolution test

Post by pgimeno »

slime wrote: Tue Sep 28, 2021 11:28 pm Personally I'd recommend customizing love.run rather than monkeypatching, mostly because the latter tends to make code less predictable in general.
My experience is the opposite, considering how many times love.run has changed over the history of Löve.
grump
Party member
Posts: 813
Joined: Sat Jul 22, 2017 7:43 pm

Re: love.timer.sleep resolution test

Post by grump »

slime wrote: Tue Sep 28, 2021 9:32 pm What would you set in love.conf other than 0 or 1/1000? I suppose you just mean a toggle rather than specifying the duration?
Consistency with vsync setting. I can't give you a better reason why it should be a number value instead of a toggle, but I also can't think of a reason why you'd need a vsync value > 1. There's probably some weird use case where it would be handy.
pgimeno wrote: Tue Sep 28, 2021 10:26 pm Anyway, that sleep doesn't really bother me. If I have to remove it (hasn't been the case so far), I can just monkey-patch love.timer.sleep.
It doesn't bother me either 99% of the time, and for normal games I usually don't care. But in the rare situations when that time really mattered and I wanted to get rid of it at least temporarily, it was always a real hassle to do so.

Monkey-patching sleep hasn't even crossed my mind tbh.
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests