Hi guys, I recently notice that the CPU used by the love engine is round 13% on my computer. compared to other games like WOW is 5%.
So is there some way to reduce it? I also checked other engines like mono game, unity, it's all nearly the same round 13%. Is this just a normal case in today's engine ?
how to reduce CPU usage ?
Re: how to reduce CPU usage ?
You may decrease CPU usage by decreasing FPS. It's really easy!
Code: Select all
function blockFPS(max,dt) -- Call this function in love.update
if dt < 1/max then
love.timer.sleep(1/max-dt)
end
end
function love.update(dt)
blockFPS(24 --[[Maximum FPS]],dt --[[Deltatime]])
--Something
end
Re: how to reduce CPU usage ?
How long is your code?
Re: how to reduce CPU usage ?
You can activate VSYNC in your games conf.lua.wahaha wrote: ↑Wed Oct 18, 2017 3:26 am Hi guys, I recently notice that the CPU used by the love engine is round 13% on my computer. compared to other games like WOW is 5%.
So is there some way to reduce it? I also checked other engines like mono game, unity, it's all nearly the same round 13%. Is this just a normal case in today's engine ?
Otherwise loves main loop runs without being delayed.
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: how to reduce CPU usage ?
By any chance, do you have an 8-core CPU? 100 divided by 8 is 12.5, pretty close for your löve app to gobble up one core completely; enabling vsync is one solution, but even then, drivers may cause busy-waiting if not implemented differently, which would get you back to square one.
Also please don't do what TC1061 suggests; the default love.run already calls love.timer.sleep with 0.001 as parameter, meaning the top speed the game loop spins is around 1000 (FPS); if the vsync method doesn't work, you could redefine love.run to wait more, 1/60 if you want 60 FPS, etc., or use an accumulator variable that you add dt to, and only run love.update and love.draw if that goes over 1/60 or similar.
Also please don't do what TC1061 suggests; the default love.run already calls love.timer.sleep with 0.001 as parameter, meaning the top speed the game loop spins is around 1000 (FPS); if the vsync method doesn't work, you could redefine love.run to wait more, 1/60 if you want 60 FPS, etc., or use an accumulator variable that you add dt to, and only run love.update and love.draw if that goes over 1/60 or similar.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: how to reduce CPU usage ?
Why don't do? My solution isn't bad. It really reduces CPU usage. Maybe 24 FPS is too low ... But your solution is also good.zorg wrote: ↑Wed Oct 18, 2017 12:55 pm By any chance, do you have an 8-core CPU? 100 divided by 8 is 12.5, pretty close for your löve app to gobble up one core completely; enabling vsync is one solution, but even then, drivers may cause busy-waiting if not implemented differently, which would get you back to square one.
Also please don't do what TC1061 suggests; the default love.run already calls love.timer.sleep with 0.001 as parameter, meaning the top speed the game loop spins is around 1000 (FPS); if the vsync method doesn't work, you could redefine love.run to wait more, 1/60 if you want 60 FPS, etc., or use an accumulator variable that you add dt to, and only run love.update and love.draw if that goes over 1/60 or similar.
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: how to reduce CPU usage ?
Because calling love.timer.sleep (more than once each frame) should best be avoided, since it blocks execution.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: how to reduce CPU usage ?
thanks for the help. your right, I just added this " t.window.vsync = false " , now my cpu usage <= 1.zorg wrote: ↑Wed Oct 18, 2017 12:55 pm By any chance, do you have an 8-core CPU? 100 divided by 8 is 12.5, pretty close for your löve app to gobble up one core completely; enabling vsync is one solution, but even then, drivers may cause busy-waiting if not implemented differently, which would get you back to square one.
but this make some animation run fast, i need check delta time for more details, just a quick reply. thanks all
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: how to reduce CPU usage ?
Yeah, you should either use dt in your code to ensure that everything runs equally fast on different computer configs, or implement a fixed timestep; accumulating dt in a variable until it's more than the delay you want (usually 1/60), then do an update once, and decrease the value by that amount.wahaha wrote: ↑Wed Oct 18, 2017 5:22 pmthanks for the help. your right, I just added this " t.window.vsync = false " , now my cpu usage <= 1.zorg wrote: ↑Wed Oct 18, 2017 12:55 pm By any chance, do you have an 8-core CPU? 100 divided by 8 is 12.5, pretty close for your löve app to gobble up one core completely; enabling vsync is one solution, but even then, drivers may cause busy-waiting if not implemented differently, which would get you back to square one.
but this make some animation run fast, i need check delta time for more details, just a quick reply. thanks all
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Who is online
Users browsing this forum: Bing [Bot] and 12 guests