Closed dannyko closed 10 years ago
added a Factory class and did some optimization, framerate seems to be pretty steady at 60 fps. also removed some extra callbacks from dronewar, wallball, and spacepong games. Overall, the performance & memory management have been improved sufficiently that we can close this issue, for now. Will reopen later when we want to do more optimizing...
I just learned about garbage collection overhead due to object creation / memory churn in JS and how it affects peformance in HTML5 games in particular, even simple things like splice, pop, and literals like {} create new objects... any time the "new" keyword is used, a new object is being created. We need to "pre allocate" or reuse objects as much as possible.
Since we don't want to go too extreme on minimizing garbage collection, my plan is to start with a dynamic allocation + reuse approach, where new objects are only created if an unused one is not available in the dynamic "pool" and once an object is "done" it goes in the "pool" rather than getting "destroyed" or collected by the GC.
That way, there won't need to be any static pre-allocation, but at the same time, we should be able to avoid creating any new objects if there is one that can be easily reused.
We can use the profiler to work from the top-down on the most expensive GC related churn issues first.
see:
http://www.htmlgoodies.com/html5/client/high-performance-garbage-collector-friendly-code.html#fbid=T3Okal6Nvcu
and
https://www.scirra.com/blog/76/how-to-write-low-garbage-real-time-javascript
plus
https://github.com/martinwells/gamecore.js
as well as
http://beej.us/blog/data/object-pool/
and also
https://github.com/mbostock/d3/commit/bef1ccb94ada61807f4e423a6ed2168cfebaf821