5. Some JS History
Brendan Eich, the lead designer
Scheme + Self with C syntax
Mocha LiveScript by Netscape (‘95)
6. Some JS History
Brendan Eich, the lead designer
Scheme + Self with C syntax
Mocha LiveScript by Netscape (‘95)
JavaScript by Netscape and Sun (’96)
7. Some JS History
Brendan Eich, the lead designer
Scheme + Self with C syntax
Mocha LiveScript by Netscape (‘95)
JavaScript by Netscape and Sun (’96)
JScript by Microsoft (‘96)
8. Some JS History
Brendan Eich, the lead designer
Scheme + Self with C syntax
Mocha LiveScript by Netscape (‘95)
JavaScript by Netscape and Sun (’96)
JScript by Microsoft (‘96)
ECMAScript by ECMA International (Nov ’96)
9. JavaScript is highly
dynamic!
no-class definitions and prototype-based inheritance
10. function Base(args){ ... }
Base.prototype.myFirstMethod = function(){ ... }
function Super(args){ ... }
Super.prototype = new Base();
Super.prototype.myMethod = function() { ... }
Super.myStaticMethod = function(){ ... }
11. function Base(args){ ... }
Base.prototype.myFirstMethod = function(){ ... } var s = new Super();
function Super(args){ ... } s.myMethod();
Super.prototype = new Base(); s.myFirstMethod();
Super.prototype.myMethod = function() { ... }
s.myStaticMethod();
Super.myStaticMethod = function(){ ... }
12. Super
prototype
new
Base() myMethod = function(){}
myStaticMethod = function(){}
function Base(args){ ... }
Base.prototype.myFirstMethod = function(){ ... } var s = new Super();
function Super(args){ ... } s.myMethod();
Super.prototype = new Base(); s.myFirstMethod();
Super.prototype.myMethod = function() { ... }
s.myStaticMethod();
Super.myStaticMethod = function(){ ... }
13. new
Super Object()
prototype
prototype
new
Base() myMethod = function(){}
myStaticMethod = function(){}
function Base(args){ ... }
Base.prototype.myFirstMethod = function(){ ... } var s = new Super();
function Super(args){ ... } s.myMethod();
Super.prototype = new Base(); s.myFirstMethod();
Super.prototype.myMethod = function() { ... }
s.myStaticMethod();
Super.myStaticMethod = function(){ ... }
14. Problems with JS
• JS is dynamic, objects are hash tables
• Properties may change at runtime
• Prototype chain may change at runtime
• We have eval (changes the context)
15. V8 Design Goals
• Make large object-oriented JS programs
perform well
• Faster property access
• Faster function calls
• Faster and more scalable memory
management
16. V8 History
• Initial design by Lars Bak in 2006
• Released and open sourced in 2008
• Significant appearances: Being shipped
inside Google Chrome and node.js
18. JIT Compiling
• Adopted by other JavaScript engines too!
• No intermediate code.
• Methods are compiled upon access.
• HotSpot-like JIT decisions
19. Hidden classes
In less dynamic languages such as Java,
+ 0x00000020 int x = 6
+ 0x00000060 int y = 1
+ 0x00000080
area() {
return x * y;
}
20. Hidden classes
In less dynamic languages such as Java,
+ 0x00000020 int x = 6
+ 0x00000060 int y = 1
+ 0x00000080
area() {
return x * y;
}
Attribute access costs just a few CPU instructions!