JavaScript object pooling for canvas particles

An ongoing experiment to learn and understand the advantages and eventual drawbacks of object pooling in JavaScript

Today I would like to present you an experiment I started some weeks ago. While working on my Qoopido.js1 library I came to the point where I thought about general optimizations in regards to performance and memory consumption. Those of you that frequently read my articles and/or explored my GitHub repository might already have realized that the concept Qoopido.js uses for its object inheritance is rather slow as long as browser vendors do not start to optimize their implementations in this respect. In my eyes this problem is not really relevant for Qoopido.js in general but it is or might become for certain modules which have the tendency to be created in huge amounts.

So I started to read about and finally implemented mechanisms to allow object pooling within the library itself but which are modules as well so can be utilized anywhere. By the time of this writing there are 4 different types of pools available:

  • Arrays
  • Objects
  • DOM elements (which is sort of a "combined meta pool")
  • Modules

Judging the results or the question for real world benefits

Implementation itself was fairly straight forward but I now had something I wanted to judge and compare to the previous state. I experimented with jsperf only to realize that something solely built for performance comparisons is not the right tool for the job.

So I started to develop a demo2 on CodePen that went through numerous iterations already but which has reached a state I would personally say is a good testing environment and playground. From my personal observations I would say there really are advantages using object pooling in certain (mostly game related) conditions in regards to memory consumption, garbage collection and therefore resulting FPS as well.

What I would really love to see are your very own conclusions and feedback on this matter. I would therefore ask anyone interested to fork the following pen and give feedback either in the comments section here or on CodePen!