Skip to content

Instantly share code, notes, and snippets.

@jdalton

jdalton/polymorphic-inline-caching.js Secret

Last active Aug 29, 2015
Embed
What would you like to do?
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});
// A different type. Runs slower because of an inline cache miss,
// but we’ll create a new cache entry for Type {a,b,c}
foo({a: 5, b: 6, c: 7});
// Hurray! Faster property access because inline cache for Type {a,b,c} exists
foo({a: 7, b: 8, c: 9});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment