Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

7 years ago by vincentpiel

Hi,

in any case anyone is interested, i wrote an article about pooling here:

http://gamealchemist.wordpress.com/2013/02/02/no-more-garbage-pooling-objects-built-with-constructor-functions/

Basically, pooling is recycling objects to avoid memory allocation / garbage collection.

I then applied this pattern to the ig.Classes, the article is here :

http://gamealchemist.wordpress.com/2013/05/04/pooling-with-init-lets-throw-impactjs-classes-in-the-pool/

And the code is here :

https://github.com/gamealchemist/Javascript-Pooling

Let me know if it happens to help you with your game !

7 years ago by Joncom

Thank you for taking the game to write this up. Very interesting.
I have not yet found the garbage collection "hit" on performance to be too bad.
But I suspect I might at some point, and I'll have this article bookmarked. :)

Edit

Does this method improve performance by preventing garbage collection from taking place, and thus uses more memory?

7 years ago by vincentpiel

Hello,
Thx for your comments !
As for performances, yes pooling makes you both avoid memory allocation and garbage collection, which is noticeable with a big number of pooled objects.
For the memory use, sure you have to be careful : a too big pool juste waste memory for nothing. So one has to adjust, looking at the createdCount at the end of a game session. And obviously you might un-reference the pool at any time to have its memory reclaimed (i wonder if i should precise that in the post).

6 years ago by John

I've tried using your plugin but keep getting this error {

Uncaught TypeError: Object function Class(){if(!initializing){if(this.staticInstantiate){var obj=this.staticInstantiate.apply(this,arguments);if(obj){return obj;}}
for(var p in this){if(typeof(this[p])=='object'){this[p]=ig.copy(this[p]);}}
if(this.init){this.init.apply(this,arguments);}}
return this;} has no method 'setupPool'
ig.Game.extend.init
Class
ig.System.ig.Class.extend.setGameNow
ig.System.ig.Class.extend.setGame
ig.Loader.ig.Class.extend.end
ig.Loader.inject.end loader.js:27
(anonymous function)
(anonymous function)

}

Any idea what's going on?

6 years ago by vincentpiel

1) Are you sure you require() the module before using it ?
2) If you want to auto-pool entity (meaning : you don't have to change a thing to make it work if you are using only spawnEntity and kill with your entities)
you have to call ga.autoPoolEntities();

On the other hand, if you use pooling on an ig.Class which is not an entity, it will be your responsibility to create them using MyClass.pnew(...), and to dispose of the instances with myInstance.pdispose();

6 years ago by John

Yes and yes, It's all working great now. My game runs faster and is no longer jittery on older devices. Thanks for your help.
Page 1 of 1
« first « previous next › last »