Lag spikes in Fedora 36 KDE

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.
User avatar
pyxledev
Prole
Posts: 23
Joined: Tue Jul 26, 2022 2:19 pm
Contact:

Lag spikes in Fedora 36 KDE

Post by pyxledev »

I recently switched my daily driver from ZorinOS (Ubuntu-based) to Fedora 36 (KDE Spin) and cloned my project repository and tested it. However when I switched to fullscreen or scaled up the window dimensions the performance decreased, which I never experienced in ZorinOS. I also updated my drivers & system and disabled vsync but that didn't seem to fix it. Does anybody know about this?

Repo link: https://github.com/zerpnord/blockdash/
Attachments
blockdash.love
(496.12 KiB) Downloaded 106 times
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: Lag spikes in Fedora 36 KDE

Post by Andlac028 »

It looks like you have some memory leak (it uses more RAM each game), try checking if you are not creating images, shaders or other object more times
Memory usage after few games
Memory usage after few games
Screenshot from 2022-09-21 20-30-18.png (2.75 KiB) Viewed 3112 times
EDIT: I kept the game running while writing this comment and it allocated 1.1 GB of RAM
Last edited by Andlac028 on Wed Sep 21, 2022 7:00 pm, edited 3 times in total.
User avatar
pyxledev
Prole
Posts: 23
Joined: Tue Jul 26, 2022 2:19 pm
Contact:

Re: Lag spikes in Fedora 36 KDE

Post by pyxledev »

Update: Running the game as super user seemed to fix the issue, but now the audio doesn't work and prints the following:

Code: Select all

error: XDG_RUNTIME_DIR not set in the environment.
Could not open device.
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: Lag spikes in Fedora 36 KDE

Post by Andlac028 »

After looking into your code, I found that you are frequently using love.graphics.setNewFont, which creates new Font each frame (this is CPU and memory intensive). See big warning on wiki page about creating objects in love.draw.

To solve this issue, use love.graphics.newFont once for font and save it somewhere and then use love.graphics.setFont like:

Code: Select all

FONT_NORMAL = love.graphics.newFont('something.ttf', 12)

-- your code ...

function someEntity.draw()
  -- and in draw functions, use
  love.graphics.setFont(FONT_NORMAL)
  -- instead of love.graphics.setNewFont
  
  -- more your code
end
These are places using love.graphics.setNewFont: https://github.com/Zerpnord/BlockDash/s ... setNewFont
Last edited by Andlac028 on Wed Sep 21, 2022 6:57 pm, edited 3 times in total.
User avatar
pyxledev
Prole
Posts: 23
Joined: Tue Jul 26, 2022 2:19 pm
Contact:

Re: Lag spikes in Fedora 36 KDE

Post by pyxledev »

Andlac028 wrote: Wed Sep 21, 2022 6:31 pm It looks like you have some memory leak (it uses more RAM each game), try checking if you are not creating images, shaders or other object more times Screenshot from 2022-09-21 20-30-18.png

EDIT: I kept the game running while writing this comment at it allocated 1.1 GB of RAM
It seems like that's one of the issues but not the main factor, because when I ran sudo love . instead of love . it seemed to fix the majority but the audio was gone. That memory leak is probably caused by the asset manager, because it seems like I ran assets.load() everytime a game started. Thanks 👍
User avatar
pyxledev
Prole
Posts: 23
Joined: Tue Jul 26, 2022 2:19 pm
Contact:

Re: Lag spikes in Fedora 36 KDE

Post by pyxledev »

Andlac028 wrote: Wed Sep 21, 2022 6:42 pm After I looked into code, I found that you are frequently using love.graphics.setNewFont, which creates new Font each frame (this is CPU and memory intensive). See big warning on wiki page about creating objects in love.draw.

To solve this issue, use love.graphics.newFont once for font and save it somewhere and then use love.graphics.setFont like:

Code: Select all

FONT_NORMAL = love.graphics.newFont('something.ttf', 12)

-- your code ...

function someEntity.draw()
  -- and in draw functions, use
  love.graphics.setFont(FONT_NORMAL)
  -- instead of love.graphics.setNewFont
  
  -- more your code
end
These are places using love.graphics.setNewFont: https://github.com/Zerpnord/BlockDash/s ... setNewFont
Is there a way to change the font size during loop? It's one of the main factors I used setNewFont().
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: Lag spikes in Fedora 36 KDE

Post by Andlac028 »

pyxledev wrote: Wed Sep 21, 2022 6:43 pm It seems like that's one of the issues but not the main factor
In main menu, setNewFont creates 1 Font for every button every frame, that is 180 Fonts per second (when you have 60 FPS and 3 buttons), which is huge waste of resources
User avatar
pyxledev
Prole
Posts: 23
Joined: Tue Jul 26, 2022 2:19 pm
Contact:

Re: Lag spikes in Fedora 36 KDE

Post by pyxledev »

Andlac028 wrote: Wed Sep 21, 2022 6:47 pm
pyxledev wrote: Wed Sep 21, 2022 6:43 pm It seems like that's one of the issues but not the main factor
In main menu, setNewFont creates 1 Font for every button every frame, that is 180 Fonts per second (when you have 60 FPS and 3 buttons), which is huge waste of resources
Aw man, I thought the garbage collector could take care of this
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: Lag spikes in Fedora 36 KDE

Post by Andlac028 »

pyxledev wrote: Wed Sep 21, 2022 6:44 pm Is there a way to change the font size during loop? It's one of the main factors I used setNewFont().
In your case, you are mainly using constant size font, so just create more fonts on start with different sizes, like

Code: Select all

FONT_MINECRAFTIA_14 = love.graphics.newFont("fonts/Minecraftia-Regular.ttf", 14)
FONT_MINECRAFTIA_22 = love.graphics.newFont("fonts/Minecraftia-Regular.ttf", 22)
FONT_MINECRAFTIA_24 = love.graphics.newFont("fonts/Minecraftia-Regular.ttf", 24)

-- and then use
love.graphics.setFont(FONT_MINECRAFTIA_14)
-- instead of 
love.graphics.setNewFont("fonts/Minecraftia-Regular.ttf", 14)
The only chase when you are using dynamic font size is in damageNumber, but there you can just create some fonts with different sizes and set the appropriate font based on the size.

It is way better to create 50 fonts with different sizes on start, than new font every frame (that is 60 fonts per second with 60 FPS) like:

Code: Select all

FONTS_MINECRAFTIA = {}

-- create fonts with sizes from 10px to 50px
for size = 10, 50 do
  FONTS_MINECRAFTIA[size] = love.graphics.newFont("fonts/Minecraftia-Regular.ttf", size)
end

-- and then use
love.graphics.setFont(FONTS_MINECRAFTIA[some_computed_font_size])
Last edited by Andlac028 on Wed Sep 21, 2022 6:57 pm, edited 2 times in total.
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: Lag spikes in Fedora 36 KDE

Post by Andlac028 »

pyxledev wrote: Wed Sep 21, 2022 6:48 pm Aw man, I thought the garbage collector could take care of this
Yes, it takes care of it, but you are just creating so huge amount of new fonts, that it can't keep up with it

You can use collectgarbage() to force garbage collector run (it is also called automatically), but it is good to solve the root cause of problem, as it also involves wasting CPU time, just by creating a ton of new identical fonts
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 52 guests