Skip to content

Instantly share code, notes, and snippets.

@jdalton
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdalton/117baac21b8fc39ed0d5 to your computer and use it in GitHub Desktop.
Save jdalton/117baac21b8fc39ed0d5 to your computer and use it in GitHub Desktop.
Example for polymorphic inline caching
function foo(o) {
//Two call sites in the code below where inline caches would be created,
//one each to access property `a` and `b`
return o.a + o.b;
}
// Initial call creates inline cache for Type {a,b}
foo({a: 1, b: 2});
// Hurray! Faster property access because inline cache for Type {a,b} exists
foo({a: 3, b: 4});
// Despite being a different type, with Equivalent Object Type Specialization,
// the call sites in the function foo will treat the following object
// equivalent with the above two, as a and b are at the same relative slot
// locations in the object layout. The call will execute faster than the speedup
// provided by polymorphic caches.
foo({a: 5, b: 6, c: 7});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment