Skip to content

Instantly share code, notes, and snippets.

@mraleph
Last active August 29, 2015 14:18
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 mraleph/141f0ed76bd24fb28243 to your computer and use it in GitHub Desktop.
Save mraleph/141f0ed76bd24fb28243 to your computer and use it in GitHub Desktop.
function bar(x) {
try { // just to prevent inlining
return x;
} catch (e) { }
}
function foo(o) {
var sum = 0;
for (var i = 0; i < 10; i++) {
sum += bar(o.x); /* o.x will not be hoisted out of the loop */
/* but corresponding map check would be *removed* */
/* so V8 partially understands immutability of the hidden class of o */
}
return sum;
}
var o = Object.freeze({x: 10});
for (var j = 0 ; j < 10000; j++) {
foo(o);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment