sbat Posted July 2, 2013 Share Posted July 2, 2013 Can you please share your experience: if pooling/caching normal, non-DOM JavaScript objects worthed it in mobile browsers for your projects? I am speaking about 2 object per second coming and dying, like explosion or new enemy (not 500-bullet-hell). I come from Flash and Java background, and recommendations there are different:In Flash, it is advised to pool and thus minimize number of mark&sweep passes. In modern Java, it is advised not to interfere with Java GC. Fast dying object (like explosion) will be handled very efficiently, long living will suffer some performance hits as it is copied between GC generations. I will probably do some simple tests myself, but your experience will be really helpful! Quote Link to comment Share on other sites More sharing options...
Mat Groves Posted July 2, 2013 Share Posted July 2, 2013 Object pooling really makes things a lot faster in js. Creation and deletion of objects is a quite expensive so I would highly recommend it for mobile games. Pretty much EVERY object was pooled in our game - http://www.goodboydigital.com/runpixierun/ I have found it makes a massive difference Quote Link to comment Share on other sites More sharing options...
Gio Posted July 2, 2013 Share Posted July 2, 2013 I believe the theory is that most javascript garbage collectors have two generations of objects - those who don't live long enough are collected more frequently and efficiently, pretty much like Java. In practice though, creating and deleting objects continuosly makes quite a big difference, and it's a good idea to avoid it when possible. But to be hoest, with just a couple of objects per frame I don't think it's going to make any real difference. Get a dozen objects, and it may start to appear in your profiling. With hundreds of objects per frame it's going to be very noticeable. It also really depends on the size of these objects. If they're small (and all of a similar size), memory defragmentation doesn't happen frequently, and when it does happen it's pretty fast. Quote Link to comment Share on other sites More sharing options...
Straker Posted July 2, 2013 Share Posted July 2, 2013 HTML5 Rocks put out an article discussing Object Pooling that's a good read. Object pooling is generally helpful in programming languages that have poor GC (such as JavaScript) and can be more hurt than helpful in programming languages that have good GC (such as Java). But like any optimization technique, it depends on your application. Large objects with lots of processing can benefit more from an object pool than small objects with little processing. But as Gio said, it all depends on what you're doing in you're application. Sometimes if you have a bunch of small objects of different types, you can create one object pool to handle all the different objects. This can be helpful because you don't have to create multiple object pools but still can gain the benefit of manual memory management. Quote Link to comment Share on other sites More sharing options...
doobdargent Posted July 11, 2013 Share Posted July 11, 2013 That HTML5 Rocks article is really good.In a game I made 6 months ago, I started with an Object Pool for the bullets but removed it because I was not seeing any performance improvement.I think I did it poorly and forgot to remove the reference to the object or something. I'll give it another go on later games. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.