Love CPU usage

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Love CPU usage

Post by TechnoCat »

Well, not that I'm really contributing anything, but I see CPU grabbing as a common practice among games. I even expect it when I open a game.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Love CPU usage

Post by Jasoco »

TechnoCat wrote:Well, not that I'm really contributing anything, but I see CPU grabbing as a common practice among games. I even expect it when I open a game.
Ditto. I see games as a "This is what I do, and I don't do anything else" application. Most games are designed to be the main thing you use on the computer when running them. Or in the case of a console, the ONLY thing you do on the device. Unless it's a small windowed game that you play casually, it should be entitled to use all the processor and resources it can grab.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Love CPU usage

Post by Robin »

Jasoco wrote:Unless it's a small windowed game that you play casually, it should be entitled to use all the processor and resources it can grab.
LÖVE games are often casual, though.
Help us help you: attach a .love.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Love CPU usage

Post by BlackBulletIV »

Jasoco wrote:it should be entitled to use all the processor and resources it can grab.
For AAA titles that works fine (they usually use a tonne of resources anyway), but for anything else, well... not really.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Love CPU usage

Post by Ryne »

You could always get [not a pentium 4] that should do the trick, that processor is 9 years old now.

Also, what constitutes as "plenty of ram". Love isn't all that demanding, but I can see it not working depending on ram-amount, or possibly the video card.
@rynesaur
User avatar
ChicoGameDev
Citizen
Posts: 70
Joined: Thu Feb 14, 2019 6:02 pm
Location: Switzerland
Contact:

Re: Love CPU usage

Post by ChicoGameDev »

Hello everybody,

This a very old topic but it is still an "issue". I've put this piece of code in my main update function :

Code: Select all

function love.update(dt)
	next_time = next_time + min_dt

	[...]

	local cur_time = love.timer.getTime()
   		if next_time <= cur_time then
        		next_time = cur_time
        		return
    		end
	love.timer.sleep(next_time - cur_time)
end
Just as kindly suggested on the love2D Wiki to limit FPS. My min_dt is set on 1/60 for 60fps

It's working great but what I'm concerned about is that LÖVE.app still takes ~103% of my processor.

Just for information my vSync is enabled too.

Do someone have the secret key for avoiding love2D to take over my CPU ?

Thanks


Regards
Lionel Leeser

Luven : https://github.com/chicogamedev/Luven

--

Always keep Game Dev as a passion.
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Love CPU usage

Post by pgimeno »

ChicoGameDev wrote: Sat Aug 29, 2020 10:19 am Just as kindly suggested on the love2D Wiki to limit FPS. My min_dt is set on 1/60 for 60fps

It's working great but what I'm concerned about is that LÖVE.app still takes ~103% of my processor.

Just for information my vSync is enabled too.

Do someone have the secret key for avoiding love2D to take over my CPU ?
My best guess is that you graphics driver implements vsync with a busy (polling) loop, rather than with an idle (interrupt-based) loop, therefore most of the CPU time is spent by the driver checking for vsync. This might be caused either by the graphics card's hardware not supporting interrupts, or by the driver itself being crappy.

If my guess is right, just disabling vsync, while keeping the sleep just as you mention above, should solve the issue.

The second possible cause is that your program is complex enough as to take 1/60th of a second per frame or more. If you still get 100%+ CPU after disabling vsync, you can test this by checking the CPU consumption with a program that disables vsync and implements the sleep method that you mention, but that does nothing else otherwise. If it still uses 100%+ CPU, then the driver or graphics card is most likely to blame. If it uses very little CPU, it may be that your program is too complex and is using up all CPU time every frame.

Another useful trick is to check the FPS of your program using the window title bar: love.window.setTitle(tostring(love.timer.getFPS())) - if it's under 60, it's your program that is eating all that CPU.
User avatar
ChicoGameDev
Citizen
Posts: 70
Joined: Thu Feb 14, 2019 6:02 pm
Location: Switzerland
Contact:

Re: Love CPU usage

Post by ChicoGameDev »

Hey,

Thanks for your answer I'm currently on a Macbook Pro and even an empty application with vsync off and just the sleep the CPU is up to ~103% here is the love file for testing purpose.

test_cpu.love
(1.57 KiB) Downloaded 226 times

For the FPS as I said I have a text ingame to show it and it's really a strong and stable 60 fps.

So is it a bug on MacOS or is it normal?

What result do you guys have on Windows?


Thanks a lot


Regards
Lionel Leeser

Luven : https://github.com/chicogamedev/Luven

--

Always keep Game Dev as a passion.
MrFariator
Party member
Posts: 512
Joined: Wed Oct 05, 2016 11:53 am

Re: Love CPU usage

Post by MrFariator »

On my Windows machine the .love you attached at most only uses 1% of my CPU, most of the time doesn't register even that. Even when I modify the code to output something to console, or do some operations, it doesn't budge. Didn't check if it maintains 60fps properly.

However, I see you are trying to implement your frame rate limiter inside the love.update. Generally I've seen people doing that by supplying their own love.run code. Not entirely sure, but having that love.timer.sleep inside your love.update, in tandem with love.run's own, might be causing issues. Another consideration is that even if your love.update doesn't do anything, and the GPU driver your Macbook Pro has is bad like pgimeno suggests, maybe modify love.run to only change the contents of the screen when love.update has finished a successful run. Eq. return a true/false value from love.update, and only run love.draw and such when trueish value is returned. Of course, love.graphics.present has a built-in stall if vsync is enabled.

Another personal recommendation is to check this library by bjornbytes, which properly implements the fixed timestep model. Maybe their love.run implementation might work better than your approach.
User avatar
ChicoGameDev
Citizen
Posts: 70
Joined: Thu Feb 14, 2019 6:02 pm
Location: Switzerland
Contact:

Re: Love CPU usage

Post by ChicoGameDev »

Hi,

Thanks for your answer.

Actually I did not know about love.run and I've not overwritten it.

I tried to add the library you liked me to the simple test project I've made and now it goes up to ~190% of CPU with a framerate set on 60.

The framerate is stable tho. But it's actually worth :O.

Thanks for the windows informations, Maybe someone on MacOS will see this thread and try out my little love file. Just to be sure I'm note alone...


Regards,
Lionel Leeser

Luven : https://github.com/chicogamedev/Luven

--

Always keep Game Dev as a passion.
Post Reply

Who is online

Users browsing this forum: No registered users and 210 guests