Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Generally speaking (in my personal experience), pooling objects is not going to improve <em>speed</em>. Creating objects is typically very cheap. Rather, the purpose of object pooling is to cut down on <strong>jank</strong>(<em>periodic</em> lag) caused by garbage collections.</p> <p>As a concrete example (not necessarily for JavaScript, but as a general illustration), think of games with advanced 3D graphics. If one game has an average frame rate of 60fps, that's <em>faster</em> than another game with an average frame rate of 40fps. But if the second game's fps is <em>consistently</em> 40, the graphics look smooth, whereas if the first's is often much higher than 60fps but occasionally dips down to 10fps every now and then, the graphics look choppy.</p> <p>If you create a benchmark that runs both games for 10 minutes and samples the frame rate every so often, it will tell you that the first game has better performance. But it won't pick up on the choppiness. That's the problem object pools are meant to address.</p> <p>This isn't a blanket statement that covers all cases, of course. One scenario where pooling can improve not only choppiness but also raw performance is when you are frequently allocating large arrays: by simply setting <code>arr.length = 0</code> and reusing <code>arr</code>, you can improve performance by escaping future re-sizings. Similarly, if you're frequently creating very large objects <em>that all share a common schema</em> (i.e., they have a well-defined set of properties, so you don't have to "clean" every object when returning it to the pool), you might see a performance improvement from pooling in that case as well.</p> <p>As I said, <em>generally</em> speaking though, that is not the primary aim of object pools.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload