How to speed up cocos-2d (js)

Is there a way to configure somehow cocos2d-js that it would not use some parts of code?
for example let’s say I don’t use physics, to I can turn the loops for physics etc.

cocos js is still slow… I need to speed it up.

I don’t think you will fix your speed problems by deactivating some parts of the code… it might help to reduce apk size but not a lot.

You can deactivate whatever you want in cconfig.h, just define to 0 macros there to deactivate the parts you don’t want. For example, if you want to deactivate physics, go to the lines

#ifndef CC_USE_PHYSICS
#define CC_USE_PHYSICS 1
#endif

and change the “1” into a “0”

I would be surprised if your cocos-js game is that much slower than writing your same javascript in c++ would be if you’re running it as a native app.

I would be the issues of performance are more related to something with how you are using cocos2d (such as your Node hierarchy) and how you are using javascript (are you creating a ton of unecessary javascript objects).

I’d also advise profiling your game to find out where your losses are coming from.

They will likely upgrade (go vote for it on the 3.9 release post) the SpiderMonkey to the latest in v3.10 which should also improve performance a bit.

Can you tell just by watching your game if there’s a specific set of points where it slows down? Or is it just slow overall? Also you are testing on a device when you see it running slow, or not?

Thanks guys.

I did setup the topic about upgrading to newest spider monkey. They will do that? :slight_smile:

I’ve already am reusing objects, reusing almost everything.
I have the problem that game is running smooth but from time to time it interrupts. I reduced creating objects. All are reused now. But I think the cocos js code is doing a lot of unnecessary new objects.
Also what if you have 10 other apps in the background which are using cpu now? it impacts you game right?

maybe you know how to reuse actions? it created every time a new object. It would be nice to create once and use multiplay times…

Yes it would. I’m not sure if it’s easy to reuse actions. I don’t believe it’s a supported funcationality.
Looks like you created a new topic so hopefully someone answers that one.

You may be able to use the init() method in c++, but I’m not sure how that would translate to js since usually you just use the ctor:function?

Adding reference to your post here:

yeah I analysed the JS code for actions and it looks like I can use ctor or initWithParams without creating new object. I will test it later…

Dont worry about JS performance OK? Actually, JS game run smoothly on native platforms as well as on web HTML5

It’s not truth!
In fact, we tried to implement our game (it’s a large arcade game) using javascript and then using c++ to compare performance. We used the same (as it was possible) architecture and algorithms.
Now I see that comparing on a real project C++ is much faster if you developing something more difficult than Flappy Bird.

1 Like

C++ always will be faster… Javascript is only for simple games…

1 Like