Too many nodes lag

Hi, Spawning 10,000 empty nodes in a scene without any behavior or components causes frame drops
tested on a windows machine

Empty Nodes cause lag which is weird, why have a batching system for sprites while nodes themselves cause a huge hit in performance

i thought of update(); being called on every node but i did this to every node i spawn


But to no avail :frowning:

Show how you spawn the nodes please. Are you relying on auto batching or are you manually batching nodes?

i used

for (int i = 0; i < 10000; i++)
    auto node = Node::create();

keep in mind I’m just spawning empty nodes not sprites
and performance still hits

what is addChild(), just the scene?

yep, the scene which is this->addChild(node); its the same with or without this

what about adding all of your empty nodes to a single empty node?

auto mainNode = cocos2d::Node::create();

for (int i = 0; i < 10000; i++)
    auto node = Node::create();

Adding all of the objects to a node yields the same results :roll_eyes:

This is known capability.

The engine’s Node (and thus Sprite) derived classes are meant to be used for small quantities: 100-1000 nodes. If you need higher node counts you’ll want to look into batching, ie: CCSpriteBatch (?spelling?), or manually generate the mesh yourself (vertices, indices, and associated attributes for UV texture coords, etc).

If you’re building a tiled background, for example, you’ll could look at FastTMXTileMap as well to see how the custom mesh creation works.

There are other ways to reduce node count such as using the Particle System for particle like nodes, but batching and custom meshes should probably be your main focus.

I’d be surprised a modern windows machine couldn’t do more than 10000 nodes without fps drop, but it is a side-effect of how the Node Graph is setup and processed each frame in Cocos2d. Maybe your machine is a bit older? And I suppose CPUs haven’t progressed too much and all the node graph processing is done on CPU.

yeah come to think of it you’re right!

why would i need thousands of objects when i could batch them in some way
also my computer is a decent computer but it lags because im targeting 144 FPS not 60
so the cpu has to do double if not triple the calculations, i just saw it drop to 120 FPS so yeah

Thanks for the response! :smiley:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.