ABSTRACT

Caching refers to a process where you create and initialize objects ahead of time, holding them hidden in reserve until you actually need to use them. The main justification for doing this is performance. The act of creating an object or accessing a property entails, under the hood, the execution of functions and the dynamic allocation of memory. These processes in themselves may not appreciably impact performance when invoked occasionally, here and there, but when dealing with lots of objects and large scenes, it can quickly become the source of lag and stutters. Consider Code Sample 7.1, for example, which simply resets an object’s position to the origin on each frame.