cocos2d-x
cocos2d-x copied to clipboard
Memory usage on Sprites
- cocos2d-x version: v4.0
- devices test on: Macbook Pro 13 (2019), Windows 10, Samsung Galaxy S8, Pocophone f1
- developing environments
- NDK version: 20.1.5984944
- Xcode version: 11.3.1 (11C504)
- VS version: 2017 Professional 2017 (2) 15.9.17
Now we are using cocos2d-x v3.17 in our game in production. We updated cocos from v3.17 to v4.0, but after update we have big troubles with perfomance. Difference in RAM consumption at the same scene for v3.17 and v4.0: 400-500 MB (on computers with integrated GPU). Release Android build on v4.0 work very slowly. We noticed increased memory consumption in some cocos's cpp-tests. For example in Renderer tests.
Steps to Reproduce:
- Download cocos2dx
- Compile (${PATH_TO_COCOS_2DX}/tests/cpp-tests)
- In the app open 3.1 In cocos2d-x 3.17 -- 55:Renderer -> 6:New Renderer 3.2 In cocos2d-x 4 -- 50:Renderer -> 5:New Renderer
The following code from this test. It creates 16,804 Sprite in the loop.
for (int i = 0; i < Renderer::VBO_SIZE / 3.9; ++i)
{
Sprite* sprite = Sprite::create("Images/grossini_dance_01.png");
sprite->setScale(0.1f, 0.1f);
float x = ((float)std::rand()) /RAND_MAX;
float y = ((float)std::rand()) /RAND_MAX;
sprite->setPosition(Vec2(x * s.width, y * s.height));
parent->addChild(sprite);
}
After switching to this scene in Visual Studio memory usage increased
- from 64 MB to 92.9 MB with cocos2d-x 3.17 (difference 28.9)
- from 55 MB to 134 MB with cocos2d-x 4 (difference 79)

Also we builded debug version on Android and at the same scenes
- from 135 MB to 157 MB with cocos2d-x 3.7 (difference 22)
- from 156 MB to 192 MB with cocos2d-x 4 (difference 36)

We would appreatiate if you help us to figure out the reasons of increased memory consumption and degradation of perfomance.
@minggo it looks like serious issue. Could you check it?
I will take a look.
@Mee-gu do you have any progress?
sorry about it , i focus on cocos-creator 3D these days, and i will take a look later today.
The reason why V4's Sprite takes more memories is that Sprite keeps ProgramState as its member. The ProgramState will store shader uniform data and some texture Infos. So compared to V3's Sprite, it definitely occupied more memories. Currently, there is no quick workaround to this memory issue. One possible way is to refactor ProgramState and it may take time to finish it.
@Mee-gu @minggo is it possible to increase priority and fix this issue in next 4.1 release?
Now we are using cocos2d-x v3.17 in our game in production. We updated cocos from v3.17 to v4.0, but after update we have big troubles with perfomance.
🥇 🤣
Is it possible you are using custom shaders? I've noticed in v4 if you are using a custom shader then batching will be disabled.
So, Is this issue solved now?
Hi, any update here?