Last active
August 29, 2015 14:06
-
-
Save jdalton/117baac21b8fc39ed0d5 to your computer and use it in GitHub Desktop.
Example for polymorphic inline caching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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