Caching Hidden Classes for Pre-transitioning Object Memory Layout in JavaScript
In JavaScript, the user can add properties to objects after the objects are created. This means that we cannot know how much memory will be required for an object in the future execution when the object is allocated. Thus, a typical implementation uses external property arrays, which are reallocated if more properties than their sizes are added. This reallocation increases GC frequency and may advance memory fragmentation. Furthermore, copying the contents of the old array to the new one is time consuming. To address this problem, we propose to decide the initial size of an object according to the history of objects allocated at the same “new” Instruction. This approach is common to JavaScript implementations, and for instance used in V8 with the help of so-called Mementos. We implemented this technique in eJSVM, a JavaScript VM for memory constrained systems, and evaluated it in this context.
In our version of the approach, we cache hidden classes of objects as part of the “new” instructions that create them. We use a heuristic to determine the hidden class that is most commonly used by objects from a specific allocation site, preferring hidden classes including all commonly used properties. When an object is created at a “new” instruction where a hidden class is cached, the object is given the cached hidden class and sufficient space to store all properties in the hidden class in the object. These in-object properties are initialized with a special empty value to keep JavaScript semantics. Only when a property that is not in the hidden class is added, an external array is allocated for the object. The cache is updated in the next garbage collection.
Tue 23 MarDisplayed time zone: Belfast change
12:55 - 14:30 | Optimizing Dynamic LanguagesMoreVMs at Virtual Space A Chair(s): Fabio Niephaus Hasso Plattner Institute, University of Potsdam | ||
12:55 5mDay opening | Welcome MoreVMs | ||
13:00 60mTalk | YJIT: Building a New JIT Compiler Inside CRubyMoreVMs Invited Talk MoreVMs Maxime Chevalier-Boisvert Shopify Media Attached | ||
14:00 30mTalk | Caching Hidden Classes for Pre-transitioning Object Memory Layout in JavaScript MoreVMs Tomoharu Ugawa University of Tokyo, Stefan Marr University of Kent, Richard Jones University of Kent Media Attached |