Fluury
Member
Heya.
The project I am working on uses procedural generation to generate it's levels. In said levels, NPCs and everything spawn. After the level is done, we wipe the current level setup, and create a new one over it.
Sounds simple enough - this isn't a new concept.
The problem I am running into is that at first launch of the game entering the first level, I am greeted with an FPS of 200. After playing the game, generating levels, creating instances etc. etc. and going to the first level _again_ under the exact same Seed for generation, and unfortunately, the FPS decreases. I simulated several "playthroughs" of the first area over and over again (By essentially just spawning every single enemy you'd normally encounter, and then killing them all, then just finishing the level.), came back to the first level under the same seed, and the FPS keeps decreasing. The FPS decrease isn't insanely drastic, but it roughly looks like this:
1st: 200-190 FPS.
2nd: 170-160 FPS.
3rd: 150-140 FPS.
etc. etc.
Obviously, this is a problem as the performance shouldn't change at all given it's the same setup with the same memory usage, same instances active and everything.
First Idea: There must be a Memory Leak! Apart from (afaik) Memory usage only slowing down your game once it reaches a critical point of memory usage, I did some testing.
No matter the amount of simulated playthroughs, the Memory Usage does not go over 70. From there, it sometimes depending on the area (given they vary in sizes...) it sometimes spikes up to 75, and then quickly drops down to 70 again. A memory leak would probably result in something much, much worse. So, unless I have misunderstood something, the performance loss is not caused by a Memory Leak.
Second Idea: I must not be resetting instances properly! Maybe I had forgotten to destroy certain instances, and it resulted in there being more instances active than before? After doing some simply debugging, and unfortunately, even just looking at the built-in variable instance_count, the instance_count stays the same for each first level generated under the same seed, no matter the simulated playthroughs I did before. The instances for the enemies, the walls, the floors, etc. etc. are all the same. So, it isn't that.
Third Idea: I must not be resetting asset layers properly! The generation and collision is built around instances, which means a wall is an instance. To decorate said walls and given the walls don't exactly move, when each wall spawns, they slap some sprites surrounding the wall on an asset layer. A variety of instances in this game (mostly environmental instances which do not move over the course of the level) do this - they put sprites on-the-fly on a specific asset layer. After the level is done, I'd destroy the entire asset layer (thus destroying it's contents) and also recreate it so the next area can use the empty asset layers. After testing the amount of elements which are active on each asset layer, even after several playthroughs, the number would stay the same. So it isn't this either.
And now - I am here, without a clue as to what is causing this. I use particle systems, I use paths, I use audio emitters... but all three of those things should, if I were to, say, just create them over and over again, result in a memory leak, right?
If anyone has any idea, or could even just tell me how to perhaps deal with this more efficiently, I am all ears. Thank you.
The project I am working on uses procedural generation to generate it's levels. In said levels, NPCs and everything spawn. After the level is done, we wipe the current level setup, and create a new one over it.
Sounds simple enough - this isn't a new concept.
The problem I am running into is that at first launch of the game entering the first level, I am greeted with an FPS of 200. After playing the game, generating levels, creating instances etc. etc. and going to the first level _again_ under the exact same Seed for generation, and unfortunately, the FPS decreases. I simulated several "playthroughs" of the first area over and over again (By essentially just spawning every single enemy you'd normally encounter, and then killing them all, then just finishing the level.), came back to the first level under the same seed, and the FPS keeps decreasing. The FPS decrease isn't insanely drastic, but it roughly looks like this:
1st: 200-190 FPS.
2nd: 170-160 FPS.
3rd: 150-140 FPS.
etc. etc.
Obviously, this is a problem as the performance shouldn't change at all given it's the same setup with the same memory usage, same instances active and everything.
First Idea: There must be a Memory Leak! Apart from (afaik) Memory usage only slowing down your game once it reaches a critical point of memory usage, I did some testing.
No matter the amount of simulated playthroughs, the Memory Usage does not go over 70. From there, it sometimes depending on the area (given they vary in sizes...) it sometimes spikes up to 75, and then quickly drops down to 70 again. A memory leak would probably result in something much, much worse. So, unless I have misunderstood something, the performance loss is not caused by a Memory Leak.
Second Idea: I must not be resetting instances properly! Maybe I had forgotten to destroy certain instances, and it resulted in there being more instances active than before? After doing some simply debugging, and unfortunately, even just looking at the built-in variable instance_count, the instance_count stays the same for each first level generated under the same seed, no matter the simulated playthroughs I did before. The instances for the enemies, the walls, the floors, etc. etc. are all the same. So, it isn't that.
Third Idea: I must not be resetting asset layers properly! The generation and collision is built around instances, which means a wall is an instance. To decorate said walls and given the walls don't exactly move, when each wall spawns, they slap some sprites surrounding the wall on an asset layer. A variety of instances in this game (mostly environmental instances which do not move over the course of the level) do this - they put sprites on-the-fly on a specific asset layer. After the level is done, I'd destroy the entire asset layer (thus destroying it's contents) and also recreate it so the next area can use the empty asset layers. After testing the amount of elements which are active on each asset layer, even after several playthroughs, the number would stay the same. So it isn't this either.
And now - I am here, without a clue as to what is causing this. I use particle systems, I use paths, I use audio emitters... but all three of those things should, if I were to, say, just create them over and over again, result in a memory leak, right?
If anyone has any idea, or could even just tell me how to perhaps deal with this more efficiently, I am all ears. Thank you.