Performance issue: 80% usage of a 3080 12gb? Bruh

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.
Krauly
Prole
Posts: 12
Joined: Thu Dec 08, 2022 6:12 pm

Re: Performance issue: 80% usage of a 3080 12gb? Bruh

Post by Krauly »

BrotSagtMist wrote: Mon Dec 19, 2022 4:04 pm No you dont, you dont need physics on not movable objects, they do not interact with the world, the player interacts with them.
In short you should not need to update these ever.

As for memory, as i thought: line 53 in player.lua
You are telling it to shove this picture into ram each frame. Like this game constantly just gobbles copies of that picture into it.
You need to change the reference, not reload it:

Code: Select all

A={}
A.L=load("L.png")
A.R=load("R.png")
draw(A[direction])
All right thank you a lot, I understood why Player.lua line 53 is trash, but I don't have no idea about another way to optimize the diamonds. Gotta do some research
User avatar
BrotSagtMist
Party member
Posts: 615
Joined: Fri Aug 06, 2021 10:30 pm

Re: Performance issue: 80% usage of a 3080 12gb? Bruh

Post by BrotSagtMist »

Its simple: have the player check if it touches a diamond and not have each freaking diamond check if it collides with each freaking thing on the entire map.

Colliding on tiles is quite easy: Its just a [x][y] map after all.
All you need to do is fill such grid with all diamond and then check the player position if he is on such a diamond:

Code: Select all

if Diam[math.floor(x/tilesize)][math.floor(y/tilesize)] then colission() end
It doesnt look like your map tiles align with your diamonds tho, else you could have just used the map.
obey
Krauly
Prole
Posts: 12
Joined: Thu Dec 08, 2022 6:12 pm

Re: Performance issue: 80% usage of a 3080 12gb? Bruh

Post by Krauly »

BrotSagtMist wrote: Mon Dec 19, 2022 4:24 pm Its simple: have the player check if it touches a diamond and not have each freaking diamond check if it collides with each freaking thing on the entire map.

Colliding on tiles is quite easy: Its just a [x][y] map after all.
All you need to do is fill such grid with all diamond and then check the player position if he is on such a diamond:

Code: Select all

if Diam[math.floor(x/tilesize)][math.floor(y/tilesize)] then colission() end
It doesnt look like your map tiles align with your diamonds tho, else you could have just used the map.
I fixed the the player animation, now I Load all frames once, then I swap when needed, thank you once more.
I will work on the collision now <3
Krauly
Prole
Posts: 12
Joined: Thu Dec 08, 2022 6:12 pm

Re: Performance issue: 80% usage of a 3080 12gb? Bruh

Post by Krauly »

I tought I fixed the physics and the load assets problem, but I f up something... hard.
If I run the the bat it goes smoother, even if still lagging sometimes.
But if I run the .love I get 1 fps, lol Im so bad at this
Attachments
CS50's SpeedRunner.love
(19.86 MiB) Downloaded 45 times
CS50's SpeedRunner.7z
(19.86 MiB) Downloaded 48 times
KayleMaster
Party member
Posts: 234
Joined: Mon Aug 29, 2016 8:51 am

Re: Performance issue: 80% usage of a 3080 12gb? Bruh

Post by KayleMaster »

1. You are creating a lot of garbage. Check out this graph from jprof
Capture1.PNG
Capture1.PNG (52.05 KiB) Viewed 1314 times

The green line is the memory usage. When you see that triangle graph it means the GC is trying HARD to clean up the huge amounts of garbage you are creating. That's what causes the lag spikes, around 3 MB for every 300 frames.
2. Most of your slowdown comes from two main places
Capture2.PNG
Capture2.PNG (77.31 KiB) Viewed 1314 times

The draw method is responsible for the huge slowdown, and most of the problem is with the GUI:draw(). Whatever you are doing there, it's bad
3. After we have the data from 1 and 2. we can drill down into your code. I found this piece...

Code: Select all

function GUI:showFPS()
  love.graphics.printf(
      'FPS '.. love.timer.getFPS(),
      love.graphics.newFont('FONT/LLPIXEL3.ttf',18),
      20,
      love.graphics.getHeight() - 30, 
      love.graphics.getWidth()
    )
end
function GUI:showTime()
  love.graphics.printf('TIME', love.graphics.newFont('FONT/LLPIXEL3.ttf',28), 0, 740, love.graphics.getWidth(), 'center')
  love.graphics.printf(string.format("%.3f", game.points), love.graphics.newFont('FONT/LLPIXEL3.ttf',28), 0, 740 + 40, love.graphics.getWidth(), 'center')
end
You are creating a THREE NEW FONTS EVERY FRAME.

P.S. Only create images ONCE. In your diamond class you are creating them every time you create a new Diamond instance.
I found these in a 10 minute span. You can take care of the rest.
Krauly
Prole
Posts: 12
Joined: Thu Dec 08, 2022 6:12 pm

Re: Performance issue: 80% usage of a 3080 12gb? Bruh

Post by Krauly »

I see, this is gold thank you.
Fixed those, now I will hunt the other auto inflicted griefs xd
One more question:
When should I declare variables inside :load and when outside?
User avatar
GVovkiv
Party member
Posts: 670
Joined: Fri Jan 15, 2021 7:29 am

Re: Performance issue: 80% usage of a 3080 12gb? Bruh

Post by GVovkiv »

Krauly wrote: Tue Dec 20, 2022 2:21 pm I see, this is gold thank you.
Fixed those, now I will hunt the other auto inflicted griefs xd
One more question:
When should I declare variables inside :load and when outside?
if you don't have plans to restart game (for debug purposes or your game have restart option) then it shoudn't really matter, since game will declare them once anyway. Also it depends on how and where you will declare this variables. If you want declare local variables, then you will be "forced" to, at least, declare them outside of love.load (otherwise they will be not avaliable from outside love.load) and then optinally set them at love.load or at declaration moment. If you want global variable, then it shouldn't matter at all, since you, probably, will use them at love.update, love.draw, etc, so variable will be already avaliable to them.

tl;dr:
In most cases it's just personal preferences. With my setup, i initilialise and configure libraries as globally (unless it's very scene/level dependent, where i declare it as local and delete when level is finished) avaliable variables outside of love.load, so they sits at top of main.lua, while at love.load, i start game itself: emit start signal to newly loaded scenes, so they can start doing their things (such as assets loading) and so on.
Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests