Creating a few dozen ui::Texts at once is slow, is there something I can do to speed that up?

Is there common way of creating a batch of nodes in cocos2d, especially ui::Text?

Since I’m using cocos2d::ui::Text::create, a lot of the time spent within is spent looking for fonts and getting the content size of the label, for alignment and positioning.

Without going into too much detail about my own uses, and assuming I’ve tried stuff like caching and lazy updating, is there a way to bulk-create a bunch of ui::Texts?

This is more informational than for diagnosis, but here’s a performance capture with Very Sleepy during a 10s where I’m repeatedly creating the widgets on hover. The columns are Exclusive/Inclusive/Exclusive %/Inclusive %, sorted by Inclusive time.

It creates a few Layouts, and then adds in a few dozen Texts with text content, then scans the Texts for markers for coloring, then goes through the letters and changes their colors based on those markers. Then it chooses a font name and size, then it adds each Text to the parent Layout.

I’m facing similar slowdowns, do u have a solution?

Nah, I haven’t found a good solution. Let me know if you do!

If the cost of creating a node is expensive, for whatever reason, wouldn’t it be better to remove it from the scene graph when not needed and add it back when it is needed? You would obviously retain it so it’s not released.

2 Likes

Yeah, that’s the solution once you’ve got them loaded into memory. It’s just the first-time loading that slows things down. Once they’re set up its good to go though, for sure.

My side, is when it shows (I reattach to scene), it can get slow down by 5 seconds. It’s about 200 Text items.