My game's real fps decrease the longer the game is open

chorrus

Member
So I would like to know the reasons this might be happening. I believe I have it hugely optimized and have been following all popular optimization guides. If you have any clue just tell me what you might think even if you are not sure about it, I'll look it up and do all possible tests to make sure it isn't that.

Thanks!
 
R

Rukiri

Guest
Code:
// Keep our Games FPS capped at 60
if game_get_speed(gamespeed_fps) != 60 {
    game_set_speed(60, gamespeed_fps);
}
Hard to say, can be may things. Could be your PC, too many objects on screen, etc.
What is going on in your room?
 

chorrus

Member
Thanks for answering, not really an issue in most devices but trying to make it compatible with even more. It's usually really high so it doesn't affect gameplay but in an old device might get below 60.
The thing is that in the same room, same objects, same particles, same everything the real fps won't be the same after playing it many times.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Decrease in FPS over time could be simply an instance is being created over and over... run the game in the debugger and check the instances and see if the number increases, then check your code if it does.
 

Ido-f

Member
I think memory leaks can also cause a decrease in fps.
If the memory usage also keeps rising that would be my guess for what's happening.
The memory usage can be viewed at the top right of the ide by running the game in debug mode.
 

chorrus

Member
Decrease in FPS over time could be simply an instance is being created over and over... run the game in the debugger and check the instances and see if the number increases, then check your code if it does.
Thanks Nocturne! It has nothing to do with that, I have just checked. It is actually decreasing very slowly but some of my testers have pointed this out as it is very common to play for a long period of time.

I think memory leaks can also cause a decrease in fps.
If the memory usage also keeps rising that would be my guess for what's happening.
The memory usage can be viewed at the top right of the ide by running the game in debug mode.
This might be it. Memory usage isn't increasing too much, but it slowly increases, I've done a quick 10 minute test it started at 66MB and has ended in 82MB. What might be causing this and how can i solve it?
 
This might be it. Memory usage isn't increasing too much, but it slowly increases, I've done a quick 10 minute test it started at 66MB and has ended in 82MB. What might be causing this and how can i solve it?
It could be one of many things. Most of the causes I've seen in GM are due to faulty resource handling. Some examples are:
  • Creating resources (sprites, fonts, rooms, etc.) dynamically but never deleting them
  • Creating surfaces but not freeing them with surface_free()
  • Creating data structures but never deleting them
 
Another problem I once ran into was creating and then destroying lots of arrays. I don't know if this is still a problem, but it appears that gamemaker's garbage collection couldn't keep up. So for example, based on that experience, I will never create temporary arrays to store vector or matrix math results.
 

chorrus

Member
Thanks for so many answers!
Knowing what kind of game you're working on might give us a clue as to where to look.

Does the slowdown only happen if a room or the game is restarted?
Yeah, that could help! https://www.instagram.com/chorrusgames/ Here I upload many videos about it, you can make an idea about what it is.
The slowdown is something that keeps happening until I close and open the game. It's not a huge drop, for example in my computer it might start in 2000fps and after 15 min it might be at 1200fps. Doesn't seem like something important but it is in many android devices, iOS devices are handling the game pretty well even my old iPad 4 is running it smoothly and super rarely lags(although it probably would after 1 hour playing)

  • Creating resources (sprites, fonts, rooms, etc.) dynamically but never deleting them
I do delete all other stuff you stated but this is something new to me, how should I delete sprites, font, rooms etc. I thought that happened automatically when changing rooms.
 
I do delete all other stuff you stated but this is something new to me, how should I delete sprites, font, rooms etc. I thought that happened automatically when changing rooms.
That's only if you're creating them dynamically, through a function such as sprite_create_from_surface(), font_add_sprite() or room_add().
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, as mentioned before, memory leak is a possible conclusion to take from this. So, check:
  • particle systems
  • surfaces
  • data structures
  • vertex buffers
  • vertex formats
  • buffers
  • audio streams
  • cameras
  • sprite fonts
  • sprites from surfaces
  • physics fixtures
Those are pretty much all the different dynamic resources that you can create, so if you are using ANY of these, recheck all your code related to them. Also note, if you have code in a DESTROY event to clean up any of these types of resources and the room ends, the destroy event is NOT called, and I recommend using the Clean Up event instead. This is a common misconception and I've seen quite a few memory leaks caused by people thinking that destroy is called on room end...

Also note that a small increase in memory over a long time is pretty much to be expected especially on Windows, as - even though you clear up data structures, particles, etc... - Windows will not de-allocate the memory they used immediately and will instead just re-use it, although the drop of 800fps is indeed suspicious.
 

chorrus

Member
Okay, as mentioned before, memory leak is a possible conclusion to take from this. So, check:
  • particle systems
  • surfaces
  • data structures
  • vertex buffers
  • vertex formats
  • buffers
  • audio streams
  • cameras
  • sprite fonts
  • sprites from surfaces
  • physics fixtures
Those are pretty much all the different dynamic resources that you can create, so if you are using ANY of these, recheck all your code related to them. Also note, if you have code in a DESTROY event to clean up any of these types of resources and the room ends, the destroy event is NOT called, and I recommend using the Clean Up event instead. This is a common misconception and I've seen quite a few memory leaks caused by people thinking that destroy is called on room end...

Also note that a small increase in memory over a long time is pretty much to be expected especially on Windows, as - even though you clear up data structures, particles, etc... - Windows will not de-allocate the memory they used immediately and will instead just re-use it, although the drop of 800fps is indeed suspicious.
Thanks! I'm using some of those so I'll revise them.

Thanks to everyone who has answered this topic! I'll let you know if i find out what is causing this :D
 

chorrus

Member
Thanks again to everybody, I believe this has been solved. In my case the problem was with not clearing particle systems correctly, what Nocturne pointed out of using the Clean Up event has been my solution. By the way, this event didn't exist in GMS 1 right? First time I' m using it and it's super useful. If anyone is having problems with their game check all the tips this thread has :D
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Thanks again to everybody, I believe this has been solved
Good hear! The clean up event is indeed a new feature in GMS2... We noticed that a alot of people were putting repeating code in the Game End and in the Destroy Event, so this gives you the best of both worlds in one place and also permits more flexibility. :)
 
Top