Open linshun opened 11 years ago
Because cc.Sprite, cc.Node, cc.LabelTTF has 2 sets of render mode, our current approach is defining a render specific class.
Pros and Cons: Code is harder to maintain, but performance is better.
What we want is to find an approach that is both maintainable, and performs good as well.
Current design: https://github.com/dingpinglv/cocos2d-html5/tree/Iss2072_JSPerformanceImprovement
There is an new approach: https://github.com/dingpinglv/cocos2d-html5/tree/Test_MemberFunctionRedefine
cc.Sprite = cc.Node.extend({ _canvasDraw:function(){ …………...// implement }, _webglDraw: function(){ ……………..// implement }, draw: function(){ ………..// empty },
ctor:function(webgl){ cc.Sprite.prototype.draw = webgl?cc.Sprite.prototype.drawWebGL : cc.Sprite.prototype.drawCanvas; } })
Pros: easier to maintain than the current approach, API documentation works Cons: a tiny bit of overhead in object creation
We have tested these two approaches in samples/tests/performance tests/PerformanceSpriteTest "F(1) actions". The test result is:
The performance on Firefox is almost not different. However, the new approach is lower performance than current design on Chrome.
Riq, could you please help me to forward this issue to the javascript experts?
Thanks.
Because cc.Sprite, cc.Node, cc.LabelTTF has 2 sets of render mode, our current approach is defining a render specific class.
Pros and Cons: Code is harder to maintain, but performance is better.
What we want is to find an approach that is both maintainable, and performs good as well.
Current design: https://github.com/dingpinglv/cocos2d-html5/tree/Iss2072_JSPerformanceImprovement
There is an new approach: https://github.com/dingpinglv/cocos2d-html5/tree/Test_MemberFunctionRedefine
Member function redefine:
cc.Sprite = cc.Node.extend({ _canvasDraw:function(){ …………...// implement }, _webglDraw: function(){ ……………..// implement }, draw: function(){ ………..// empty },
ctor:function(webgl){ cc.Sprite.prototype.draw = webgl?cc.Sprite.prototype.drawWebGL : cc.Sprite.prototype.drawCanvas; } })
Pros: easier to maintain than the current approach, API documentation works Cons: a tiny bit of overhead in object creation
We have tested these two approaches in samples/tests/performance tests/PerformanceSpriteTest "F(1) actions". The test result is:
The performance on Firefox is almost not different. However, the new approach is lower performance than current design on Chrome.
Riq, could you please help me to forward this issue to the javascript experts?
Thanks.