Cocos2d-x 3.0 Online Party

How about a new topic for performance related conversation?

That is a good idea, I’ll ask that it be made.

Agreed. I tend to be quite particular about performance. So I suggest for a start that anything that is called every frame or regularly should do passing by reference instead of a copy as passing by reference only passes a pointer to the reference and does not need allocation of memory space for copy

We’re doing the installer on both mac and windows these days. And in the last week, we tried to support compilation from static libraries instead from source code, to reduce the complexity for new users. @Martell your suggestion is quite good, I should consider the binary + header structure in the next week. For example, we can have a auto-compile-and-copy script to create such a structure from current cocos2d-x repo.

@walzer yes that would be great. For example the cocos.py tool could go into the package folder /bin then from anywhere on the system a user could create a project debug it run it etc.
The ability to choose between shared and static would complete this making it perfect.

I know I’ll definitely be making a package for pacman on msys2 using this structure for windows and something similar on Mac via homebrew. The best thing about these systems is the we don’t need cocos to give us 3rd party dependencies. The package manager has them all zlib libpng libjpeg etc.

If you do this I’ll see what I can do in terms of getting a few Linux distros to start providing cocos2d-x packages also :wink:

That would really help spread the engine more and would be very good PR for cocos

In terms of an installer they would only be needed on two specific setups windows via MSVC and Mac without homebrew. Might I suggest using qt installer framework for the installer it is very good and we will be using it now for new msys2 releases. It works on win Mac and Linux and is exempt from the qt license restriction on static linking.

Yes this is very important!

My test code looks like this

// .h

extern void test();

class Father
{
public:
    virtual void father();
};

class Son : public Father
{
public:
    void son();
    
    virtual void father();
};

// .cpp
void Father::father()
{
    
}

void Son::father()
{
    
}

void Son::son()
{
    
}

void test()
{
    Father *father = new Father();
    Father *son = new Son();
    
    clock_t t = clock();
    for (int i = 0; i < 100000; ++i)
    {
        father->father();
    }
    t = clock() -t;
    printf("time 1 is %f s\n", (float)t/CLOCKS_PER_SEC);
    
    t = clock();
    for (int i = 0; i < 100000; ++i)
    {
        dynamic_cast<Son*>(son)->son();
    }
    t = clock() -t;
    printf("time 2 is %f s\n", (float)t/CLOCKS_PER_SEC);
}

I tested on iPad mini. But The result was strange:

  • sometimes time 2 is less than time1
  • most times time 2 is 3-4 times of time1
  • the total time is less than 0.01 second

First of all, there are too few iterations.
Next, your methods do nothing. Depending on compilation flags, compiler is allowed to optimize your code thus there are no calls at all, since, as I’ve already said, your code has no side effects.
Here is your code with my corrections http://codepad.org/OretCQf5

Thanks for correction.
The question is that, in a real game, how many times of dynamic_cast invoked in a frame? It leads to another question, how will it affect the performance?

Here is an extract from gperf output after profiling my real game:

I’m sure that ~6.5% wasted on dynamic_cast is too much.
BTW, take a look at those 6% and 5.7% wasted on copying of Size::Size and Matrix::Matrix respectively. If you sum up all those percents it would be a huge number.

Thanks.

I will modify copying of Size and Matrix ASAP.
About the dynamic_cast issue, does it all caused by Sprite::setDirtyRecursively?

Coping issue is resolved in this pull request.

Size stayed unresolved:

Size size = _rect.size; // line #533

Yep, the most intensive utilization of dynamic_cast is there.

Good catching.
Thanks.

Fixed here https://github.com/cocos2d/cocos2d-x/pull/7190.

About dynamic_cast, i think i have to do more test.
What’s gperf? I found it here http://www.gnu.org/software/gperf/.
Could you please give me the link?

gperf should be part of osx or most any linux distro, I would think, with developer tools installed.

man gperf from a terminal.

@dotsquid - can you educate is and tell us how you used gperf to see these results? Seriously, step by step?

Oh, crap. I’m sorry, it wasn’t gperf, it was gprof with the help of android-ndk-profiler

This topic is now closed. New replies are no longer allowed.

if you wish to continue the discussion, please use