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
High CPU consumption
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
High CPU consumption
- Attachments
-
- game.love
- (1.18 MiB) Downloaded 211 times
Re: High CPU consumption
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):
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):
Re: High CPU consumption
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
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
Re: High CPU consumption
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).
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.
- Luke100000
- Party member
- Posts: 232
- Joined: Mon Jul 22, 2013 9:17 am
- Location: Austria
- Contact:
Re: High CPU consumption
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%.
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%.
Re: High CPU consumption
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?
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?
Re: High CPU consumption
That is one way to do it, but since you're iterating over coordinates anyway you can limit the coordinates in the loop parameters.
- Luke100000
- Party member
- Posts: 232
- Joined: Mon Jul 22, 2013 9:17 am
- Location: Austria
- Contact:
Re: High CPU consumption
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, ...)
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, ...)
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests