High CPU consumption

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
bphil
Prole
Posts: 3
Joined: Sun Oct 20, 2019 5:26 pm

High CPU consumption

Post by bphil »

Dear forum,

I am playing around with love and cobbled together the attached code in the process.

Now I noticed that the fan on my notebook (Carbon X1, 4xIntel(R) Core(TM) i7-7600U CPU @ 2.80GHz, 16GB ram) is starting up when I launch the game and I was wondering why that would be, given that the code is really not doing much. I looked around in the forum and

- excluded the vsync issue (or, at least my FPS is constant at 60, which I took to exclude the vsync issue);
- activated itraykov's profiler, but the output is not telling me very much, to be honest (the only thing I noted is that in comparison with the example report in the profiler's documentation, I get a lot of calls (100) for some of my functions).

So I wonder whether anyone of you could advise on what is eating up my CPU or on how to proceed looking into this.

Many thanks!
Philipp
Attachments
game.love
(1.18 MiB) Downloaded 210 times
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: High CPU consumption

Post by pgimeno »

It's the calls to love.graphics.print() which are killing it. Maybe try to use a pre-rendered Text object.

I can't advise further because I have no idea what this is about; all I see is this (cropped because it's too big):
Attachments
cropped-editor-cant-see-anything.png
cropped-editor-cant-see-anything.png (15.58 KiB) Viewed 5841 times
bphil
Prole
Posts: 3
Joined: Sun Oct 20, 2019 5:26 pm

Re: High CPU consumption

Post by bphil »

Thank you very much for your reply.

This is good news, as the numbers were just there for debug reasons (there is really not much more to this at the moment than what you saw; I am simply learning how to use the gamera and push libraries and how to correlate mouse position with places in the game).

May I ask how you determined that it's the printing of the numbers that caused the CPU consumption? Is that just a general fact about the nature of rendering text that it is demanding for the CPU or did you do an analysis of some sort, which I could repeat should similar issues arise in the future?

Thanks again and best wishes,
Philipp
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: High CPU consumption

Post by pgimeno »

bphil wrote: Mon Oct 21, 2019 6:41 am(there is really not much more to this at the moment than what you saw;
What I saw is what the image shows literally, which I cropped but I did NOT scale down. The text was not readable, and the lines were barely visible. I'm letting you know in case you want to reconsider the target screen size for people with smaller screens (mine is (1280x1024).

bphil wrote: Mon Oct 21, 2019 6:41 amMay I ask how you determined that it's the printing of the numbers that caused the CPU consumption?
I disabled parts of the program and checked CPU %, until I got there. First I disabled the call in love.update, but that caused a crash; apparently it's defining something that love.draw needs. Then I disabled the EditorDraw call in love.draw and that got totally rid of the CPU consumption. I looked in the target function and disabled it in parts; that led me to drawGrid. Lastly, the CPU consumption dropped when I disabled love.graphics.print in there.
User avatar
Luke100000
Party member
Posts: 232
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Re: High CPU consumption

Post by Luke100000 »

I assume that the CPU usage is only from preparing the text, not rendering. So, as pgimeno said, a text object should fix that. (not tested yet)

If this is not possible, then at least only draw text visible on screen. I tested this and achieved 4% CPU usage instead of 25%.
bphil
Prole
Posts: 3
Joined: Sun Oct 20, 2019 5:26 pm

Re: High CPU consumption

Post by bphil »

Thanks for pointing out the debug procedure, pgimeno.

Thank you also for your suggestion, Luke100000. As I said in my reply to pgimeno, the text is only there for debug reasons. Nevertheless, I think it's a good exercise to restrict drawing to what is visible. Given that you were able to quickly test the effect of drawing only what is visible on screen, I assume it is not very hard to integrate. How did you do it? Did you just put the love.graphics.print-call that draws the numbers into an if-clause that compares the camera coordinates with the coordinates at which the numbers would be drawn?
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: High CPU consumption

Post by raidho36 »

That is one way to do it, but since you're iterating over coordinates anyway you can limit the coordinates in the loop parameters.
User avatar
Luke100000
Party member
Posts: 232
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Re: High CPU consumption

Post by Luke100000 »

As raidho34 said, I just limited the x and y loop.

Usually drawing outside the screen (images) won't really affect the performance, this is already handled by the GPU (or something before, I'm not sure). But text requires some pre processing.

So don't check every image manually. Limit mass draws like loops or if you have complex objects with several images check only the object. But in other cases I do not recommend additional calculations. (you would also have to consider transformations, ...)
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot] and 4 guests