Skip to content

Memory usage on Sprites #20472

@vasgenashotov

Description

@vasgenashotov
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions