cocos2d-x icon indicating copy to clipboard operation
cocos2d-x copied to clipboard

Memory usage on Sprites

Open vasgenashotov opened this issue 5 years ago • 10 comments
trafficstars

  • 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:

  1. Download cocos2dx
  2. Compile (${PATH_TO_COCOS_2DX}/tests/cpp-tests)
  3. 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) cocos2d-x 3.17 cocos2d-x 4

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) image image

We would appreatiate if you help us to figure out the reasons of increased memory consumption and degradation of perfomance.

vasgenashotov avatar Mar 03 '20 07:03 vasgenashotov

@minggo it looks like serious issue. Could you check it?

crazyhappygame avatar Mar 04 '20 19:03 crazyhappygame

I will take a look.

Mee-gu avatar Mar 05 '20 02:03 Mee-gu

@Mee-gu do you have any progress?

crazyhappygame avatar Mar 10 '20 19:03 crazyhappygame

sorry about it , i focus on cocos-creator 3D these days, and i will take a look later today.

Mee-gu avatar Mar 11 '20 03:03 Mee-gu

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 avatar Mar 11 '20 14:03 Mee-gu

@Mee-gu @minggo is it possible to increase priority and fix this issue in next 4.1 release?

crazyhappygame avatar Mar 11 '20 20:03 crazyhappygame

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.

🥇 🤣

gestern avatar Mar 18 '20 23:03 gestern

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.

bolino avatar Apr 16 '20 03:04 bolino

So, Is this issue solved now?

lezard618 avatar Apr 13 '21 07:04 lezard618

Hi, any update here?

thienphuoc avatar Apr 13 '21 14:04 thienphuoc