Garbage collector stops the game[or probably disk access]
Posted: Sat Jan 06, 2018 8:14 pm
Hi.
My problem is: garbage collector is ruining performance. With 'best' setting, it freezes the game once in several seconds. Originally it freezed the game for a moment very often, which made the character movement jittery.
Why I think it's GC:
1. It's unpredictable
2. When I disable the code which generates garbage, everything runs smoothly.
What generates garbage:
Unloads of chunks of blocks. Faster movement -> more chunk unloads -> more freezes.
What I tried (unsuccessfully):
1. Various ways of calling 'collectgarbage()" method.
1.1 "Step" every frame - makes things worse than original.
1.2 "Step" with some number - even worse.
1.3 "stop" and then only doing "steps" on frames - very bad. (not sure if it was this variant which caused 20-second interrupts)
1.4 "stop" when expensive code is executed, "restart" or "step" otherwise - not helpful
2. Reusing object in pool. When individual object is measured, it's slightly faster then creating new objects. Unfortunately, there are many of them. All the memory is quickly polluted with the huge pool. GC doesn't need to collect blocks, but it probably still checks them. Anyways, performance becomes very-very bad, and it makes usage of third way of 'improvement' impossible because pool size grows bigger then the allowed lua ram.
3. Distributing garbage generation across frames. Instead of unloading all chunks at once, only one chunk is freed per frame. It prevents small stops on every chunk border, postponing it to some random 1-2 seconds freeze in the future. This 'best' performance is still very irritating.
Option to reduce game quality is not really an option, it contains only a small portion of what I wanted to implement, and it already have troubles. Option to avoid GC by making structures in FFI is also probably not an option, it will make things much more complicated and probably will ruin flexibility and extensibility.
.love file is attached.
So, my question: am I missing something? Is there anything else I can try before I give up?
My problem is: garbage collector is ruining performance. With 'best' setting, it freezes the game once in several seconds. Originally it freezed the game for a moment very often, which made the character movement jittery.
Why I think it's GC:
1. It's unpredictable
2. When I disable the code which generates garbage, everything runs smoothly.
What generates garbage:
Unloads of chunks of blocks. Faster movement -> more chunk unloads -> more freezes.
What I tried (unsuccessfully):
1. Various ways of calling 'collectgarbage()" method.
1.1 "Step" every frame - makes things worse than original.
1.2 "Step" with some number - even worse.
1.3 "stop" and then only doing "steps" on frames - very bad. (not sure if it was this variant which caused 20-second interrupts)
1.4 "stop" when expensive code is executed, "restart" or "step" otherwise - not helpful
2. Reusing object in pool. When individual object is measured, it's slightly faster then creating new objects. Unfortunately, there are many of them. All the memory is quickly polluted with the huge pool. GC doesn't need to collect blocks, but it probably still checks them. Anyways, performance becomes very-very bad, and it makes usage of third way of 'improvement' impossible because pool size grows bigger then the allowed lua ram.
3. Distributing garbage generation across frames. Instead of unloading all chunks at once, only one chunk is freed per frame. It prevents small stops on every chunk border, postponing it to some random 1-2 seconds freeze in the future. This 'best' performance is still very irritating.
Option to reduce game quality is not really an option, it contains only a small portion of what I wanted to implement, and it already have troubles. Option to avoid GC by making structures in FFI is also probably not an option, it will make things much more complicated and probably will ruin flexibility and extensibility.
.love file is attached.
So, my question: am I missing something? Is there anything else I can try before I give up?