cocos2d / cocos2d-html5

Cocos2d for Web Browsers. Built using JavaScript.
https://www.cocos.com
3.07k stars 902 forks source link

A way of saving the runtime optimizations? #3541

Closed dganzella closed 6 years ago

dganzella commented 6 years ago

Hello!

I noticed that the cocos js html5 functions are optimized A LOT as you play the game. The same methods , when called 3 or 4 times, start to run in much less time. Doesnt matter if I'm using Chrome or firefox, desktop or mobile, it always get better as game goes on.

Is there a way to save these runtime optmizations and load them in memory upon opening the game? So the first interactions are not slow.

Thanks.

Danilo

pandamicro commented 6 years ago

It's the result of great JIT compiler inside all modern JavaScript engines, unfortunately it's a runtime feature only, you can't pre compile the code, because they are supposed to be dynamic (code path, object map, inline functions, etc). The only thing similar is ASM.js and its next generation: WebAssembly, but they are designed for C++ and other compiled languages, they sort of compile the result of such native programs into byte codes (or asm.js format JS codes) that can be run by the browser

dganzella commented 6 years ago

i see. Thanks for the explanation.

Is it common practice to simulate the game briefly while 'loading' in order to increase performance? Maybe I can even build asimple input lib to record some steps and then run them before the game starts.

pandamicro commented 6 years ago

I can only say that it's not a common practice, but you can give it a try if you want.

dganzella commented 6 years ago

Thanks once more.

Playing the game by script worked wonders. Its now much faster.

Danilo