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

Discussion in 'Programming' started by chorrus, Jun 12, 2019.

  1. chorrus

    chorrus Member

    Joined:
    Jun 21, 2016
    Posts:
    84
    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!
     
  2. Rukiri

    Rukiri Member

    Joined:
    Sep 25, 2016
    Posts:
    137
    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 likes this.
  3. chorrus

    chorrus Member

    Joined:
    Jun 21, 2016
    Posts:
    84
    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.
     
  4. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,650
    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.
     
    Andy and chorrus like this.
  5. Ido-f

    Ido-f Member

    Joined:
    Feb 19, 2018
    Posts:
    105
    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 likes this.
  6. chorrus

    chorrus Member

    Joined:
    Jun 21, 2016
    Posts:
    84
    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.

    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?
     
  7. Andy

    Andy Member

    Joined:
    Jun 20, 2016
    Posts:
    180
    chorrus likes this.
  8. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,984
    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?
     
    chorrus likes this.
  9. nacho_chicken

    nacho_chicken Member

    Joined:
    Jun 21, 2016
    Posts:
    302
    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
     
    chorrus likes this.
  10. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,984
    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 likes this.
  11. chorrus

    chorrus Member

    Joined:
    Jun 21, 2016
    Posts:
    84
    Thanks for so many answers!
    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)

    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.
     
  12. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,984
    Nothing really stands out at first glance. You're not accidentally creating duplicate particle systems or types, are you? For example when starting a new room.
     
    chorrus likes this.
  13. nacho_chicken

    nacho_chicken Member

    Joined:
    Jun 21, 2016
    Posts:
    302
    That's only if you're creating them dynamically, through a function such as sprite_create_from_surface(), font_add_sprite() or room_add().
     
    chorrus likes this.
  14. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,650
    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.
     
    Andy, chorrus and Ido-f like this.
  15. chorrus

    chorrus Member

    Joined:
    Jun 21, 2016
    Posts:
    84
    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
     
  16. chorrus

    chorrus Member

    Joined:
    Jun 21, 2016
    Posts:
    84
    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
     
  17. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,650
    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. :)
     
    Phil Strahl and chorrus like this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice