Object pooling - Falmouth-Games-Academy/comp350-research-journal GitHub Wiki

Object Pooling

Object pooling is a design pattern which aims to reduce the expense caused by the acquisition and release of resources through recycling old resources that are no longer needed.

The pooling design pattern is often used as a way to combat the poor performance that can occur from rapid memory allocation and deallocation 2(https://www.raywenderlich.com/847-object-pooling-in-unity). Allocating all of the objects before gameplay starts and removing them when all of the gameplay is over removes the potential for lag spikes caused by memory allocation/deallocation.

Retrieving objects from persistent storage is a time-consuming process that can dramatically reduce system performance. It can often be better to keep a copy of all persistent objects in memory. But, in systems which have large numbers of persistent objects, this scenario may exceed the memory limitation. Hence, the primary goal of object pooling is to improve the performance by keeping a limited number of objects with more access probabilities in memory 5(https://www.researchgate.net/profile/Samira_Sadaoui/publication/220830962_A_Novel_Object_Pool_Service_for_Distributed_Systems/links/0922b4f677258812ca000000/A-Novel-Object-Pool-Service-for-Distributed-Systems.pdf). With this in mind, developers should regularly profile their program to check the amount of memory used does not exceed memory requirements. Profiling will also help to identify when deciding if object pooling is valid with the CPU/Memory tradeoff. This should especially be of consideration when dealing with Mobile device optimisation as RAM is limited.

Unity Object Pooling

A user on the stack overflow thread 3(https://stackoverflow.com/questions/37847848/unity-need-to-reset-a-pooled-object-on-return-to-pool-perhaps-using-scriptable) called 'Fattie' claims that pooling was made redundant in Unity since an update to the engine in 2014. Unity users in a separate thread 4(https://forum.unity.com/threads/is-object-pooling-redundant.453205/) point out that even with the update, there is still memory being allocated/deallocated even if it is done more efficiently. The contributors of 4(https://forum.unity.com/threads/is-object-pooling-redundant.453205/) still recommend using the pooling design pattern in a situation where there are many objects being spawned and destroyed.

This design pattern should be used on mobile because mobile phones are bad at allocating/deallocating memory see Mobile device optimisation for more.

References

[1] http://www.kircher-schwanninger.de/michael/publications/Pooling.pdf

[2] https://www.raywenderlich.com/847-object-pooling-in-unity

[3] https://stackoverflow.com/questions/37847848/unity-need-to-reset-a-pooled-object-on-return-to-pool-perhaps-using-scriptable

[4] https://forum.unity.com/threads/is-object-pooling-redundant.453205/

[5] Sadaoui, Samira, and Nima Sharifimehr. "A novel object pool service for distributed systems." OTM Confederated International Conferences" On the Move to Meaningful Internet Systems". Springer, Berlin, Heidelberg, 2006.