So I started working on a new library which I am calling FlashPools. It is an ultra generic library to handle object pooling in Flex and Air.
You can register custom pool classes against the library to handle specific class types and what not. I’m trying to make it pretty flexible yet have an easy API to integrate with.
The ease of the API does conflict a bit though with trying to make the library run as efficiently as possible – there are certain niceties that can be achieved with things like describeType that clean up the API, but adversely effect performance. describeType in particular is painful as it uses e4x, which is expensive… especially if you are doing it ~100 times per frame.
i made a simple test app that does the following on every enter frame:
- attaches up to 100 instances to a canvas control (random amount)
- randomly selects new x,y positions for the attached instances
- removes up to all of the attached instances in the canvas control (random amount)
now here is a test of that process without using object pooling. notice the cumulative instantiation count and memory usage for the BlueCircle class:
now here is another screenshot taken after running the app again, but this time with object pooling enabled. again, notice the instaniation count and memory usages for the BlueCircle class:
the reason why the instantiation counts are important is because of the processing work involved with each instantiation. basically, the less instantiations you do, the faster the app will run.
the library is still pretty early yet, but I am pretty stoked about the results so far!