Overheads of non-parent sprite nodes

Overheads of non-parent sprite nodes
0.0 0


Hi, I’m trying to make “object pool” system with using sprite nodes.
Is it take CPU or rendering process when I reserve sprite nodes which not having parent nodes?

I’m making 2D action type game wich aiming to have high frame rate. Enemy shoots many various bullets in the game. I don’t want to create and destroy sprite nodes everytime when enemy shooting the bullets, because it seems slow.
So, I’m plannning to reserve pre-created sprite nodes for general purpose. And use it when enemy shooting the bullets, with setting corresponding sprite frame and parent node. After finish using them, the node will release and back to reserve nodes.

I believe this approach called “Object pool”.

I’m worry that is there any problem that having a lot of no-parent node without using.
Also, if have any advice on this approach, please feel free to tell me.



You’ll be good, orphaned nodes don’t take up proccessor time at all.

If you’re going to have a LOT of bullets on the screen a good idea would be to put all projectile sprites into a single atlas and to put all projectile nodes in a single parent that has no other children. That way you’ll have all your bullets rendered in a single draw-call

Anyway, don’t spend too much effort on beforehand optimization, solve problems you actually face :slight_smile:


Post as information and a memorandum for myself.
I did quick test for this with my dev. environment.
Cocos creator v1.7.2,
MacBook Pro (Retina, 13-inch, Late 2013) , 2.4 GHz Intel Core i5, 8 GB 1600 MHz DDR3 memories.
Google Chrome 63.0.3239.132 (Official Build) 64bit. Canvas draw.

A. No running process.
207 fps.
B. Made 1000 nodes + cc.Sprite with simple sprite-frame with no parent. (nothing draw on screen)
190 fps.
C. Set parent with B.
120 fps.

D. Remove 1000 nodes ( removeFromParent(true) ) and
create 1000 nodes per second (new cc.Node + addComponent(cc.Sprite) with C.
59 fps.
E. Remove/ create 15000 nodes with D.
30 fps. It seems garbage correction running each few second.
F. Object Pool 1000 per second.
Remove 1000 nodes ( removeFromParent(false) ) and
re-assign 1000 nodes per second with C. (set parent, setPosition and set spriteFrame)
60 fps.
G. Object Pool 15000 per second.
Remove and re-assign 15000 nodes per second with F.
60 fps. It seems garbage correction is not running.

My conclusion is,
Object pool is certainly faster than remove/ create, but remove/ create is not so slow than I thought. Difficult to see big difference between object pool with 1000 remove/ create per second.
Don’t need more than 1000 remove/ create 1000 objects/second at normal use at game. But object pool can provide sprite reuse without almost no cost.



Just out of interest. The child you are adding is just a sprite and no code? When you are adding the the children/sprites to the pool do you set node.active = false ?


The child you are adding is just a sprite and no code?
Just sprite and no code. Since this is test.

When you are adding the the children/sprites to the pool do you set node.active = false ?
No. I never touch node.active in every cases (A-G).
I’m only setting parent and removing from parent for Object pool.



Ok. I’m thinking setting active to false would benefit performance but I haven’t done any tests on that myself so I can’t say for sure.


Setting active false for nodes make sense and I’m pretty sure that will work. Will have same performance with my implementation.

Because of the special needs of my game, a Object Manager program control all updates of the object at once, so I don’t need update() for each object. Also, I need to change parent of objects.