Using a New Optimization, 'Preemptive Inline Miss', to Dramatically Improve the Performance of Property Retrieval At Runtime
FROM THE AUTHOR: I would first like to thank you in advance for reading this idea. I appreciate feedback and general discussion, and hope that this scheme at the very least is a positive influence on V8, an already great Javscript Engine. The idea of Preemptive Inline Miss is hereby placed in the public domain to be used in any way. ABSTRACT: In the proposed method of Preemptive Inline Miss, I propose a scheme to remove the need to check for an 'inline cache miss' at property retrieval by shifting the performance penalty to the site where dynamic class modification occurs. In short we perform an 'inline cache miss' in advance for each object that references a class that was just modified. Removal of the 'inline cache miss' check brings the code closer to the execution speed of native code despite its non- static nature and works well with classes that infrequently modify their property lists. The benefit of Preemptive Inline Miss is a greater performance for common programming habits and a very easy way for developers to leverage this optimization. The trade off for Preemptive Inline Miss is an increased memory consumption. HOW IT WORKS: Preemptive Inline Miss is a simple scheme that proposes moving the performance penalty from accessing properties of an object to the site where a classes properties are dynamically modified. We accomplish this by assuming an object stores the correct hidden class offset during runtime, and upon modification of a hidden class, update the offset of all objects that reference the old class to that of the new class. In order to update the objects hidden class preemptively, a list of all objects that reference that hidden class must be held. We can accomplish this with a solitary pointer bundled with the object, used to form a linked list with all objects sharing the hidden class. The head of this list of objects is stored at the hidden class. Upon class property modification, the the following actions can take place: 1) The new hidden class is created 2) We traverse the list of objects associated with the old hidden class and update their hidden class offsets to the new hidden class (inline cache miss) 3) We move the list of objects from the old hidden class to the new hidden class A property can be safely accessed without the need to check if it is using the correct hidden class as it will have been updated directly after the hidden class was modified! The performance cost is thus paid only when exercising the dynamic nature of the language -- ie. adding or removing properties -- and need not be paid when doing the very common operation of property access. Put another way: we perform an 'inline cache miss' in advance for each object that refrences a class that was just modified. A CLEAR POINT OF OPTIMIZATION: Preemptive Inline Miss provides a very clear and easy to leverage optimization path for developers who exercise an objects dyanmic- nature as early as possible and adhere to a rigid class structure for most of the runtime of an application. It is assumed that a great number of programs also maintain a rigid class structure, which is a similar assumption that motivated V8's use of inline caching system and hidden classes [1]. THE COSTS: The cost of Preemptive Inline Miss is one of memory. A list of a hidden classes referencing objects must be held for this scheme to work. This adds a pointer reference to each object and one to each hidden class. SOURCES: [1] http://code.google.com/apis/v8/design.html Thank you for your time and consideration. -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev
