Documentation | Wally | GitHub
Pooler is a simple instance pooler. It recycles objects to prevent constant
It’s more performant to recycle objects than destroy and recreate them. Whilst the differences are small, when the time it takes adds up, your game will be a lot slower by removing and creating instances when compared to using an instance pooler. Things like bullet hell games will almost certainly require instance pooling to run fast enough since creating and destroying thousands of objects will be extremely expensive on either the server of client.
I’m aware there are other more mature and more battle-tested instance poolers out there, and a lot of people will write their own for each project. I wanted my own pooler that did what I needed it to do, and I decided to open-source it and distribute it.
Pooler is designed to take any instance type, not just parts. The majority of poolers I’ve seen can only accept parts and the ones I’ve seen that don’t do not have much customizability. I needed both, so I wrote Pooler to handle both cases. It can pool anything, but it still has the ability to use the optimized techniques for BaseParts and Models when required.
Pooler is a dead simple library to use. Your existing code might look like this:
local Debris = game:GetService("Debris") local template = Instance.new("Part") template.Anchored = false template.Material = Enum.Material.Neon template.BrickColor = BrickColor.Green() while true do local instance = template:Clone() instance.Parent = workspace Debris:AddItem(instance, 3) task.wait() end
This is obviously a very bizarre use case, but let’s roll with it. Converting this to Pooler is quite an easy task.
- Add Pooler to your script:
local Pooler = require(script.Parent.Pooler) -- or wherever your copy might be...
- Create your instance pool:
local pool = Pooler.new(template)
- Swap out your :Clone() and :AddItem() calls for the Pooler equivalents:
while true do local instance = pool:Get() instance.Parent = workspace task.delay(3, function() pool:Return(instance) end) task.wait() end