Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Benedikt Meurer
Google Munich
@bmeurer
Proprietary Proprietary
An Engines View...
Proprietary
ES2015 is cool!!!!1
Proprietary
hug
ES2015 is a
monster e
Proprietary
Maps Proxies
Promise
Classes
s
Spread
Tagged Sets TypedArray
Template s
Strings
ES2015
Lexical
Scoping
Well-
known Computed
Symbols Iteratio Property
Generato
n Names
rs
Array
Builtins Modules
Arrow
Functions
Proprietary
2.2
x
258 566
pages pages
Proprietary
Performance
Measurement
Proprietary
Old vs. New
Proprietary
Proprietary
Six-speed methodology
Based on github.com/kpdecker/six-speed by @kpdecker
Proprietary
Six-speed methodology (Example)
for-of-array.es5 for-of-array.es6
test(fn); test(fn);
Proprietary
Proprietary
How to get
involved?
Contribute to ES2015 and
beyond performance plan:
goo.gl/CNSM83
Contribute to Six-Speed:
fhinkel.github.io/six-speed
Proprietary
Destructuring
return x; 8 : Return
Proprietary
Destructuring the ES2015 way
0 : LdaTheHole
function foo6(a) { 1 : Star r6
3 : StackCheck
const [x] = a; 4 : Mov a0, r0
7 : LdaNamedProperty r0, [0], [2]
Iterator closing
Proprietary
Can I haz fast plz?
Proprietary
Destructuring the ES2015 way lets see!
1. Let iterator be a[Symbol.iterator]()
Depends on
2. Let result be iterator.next() a
5. Assign result.value to x
6. Return x
Lets consider for
example
foo6([0]);
Proprietary
Destructuring the ES2015 way Array
destructuring
1. Let iterator be a[Symbol.iterator]() Array.prototype[@@iterator]
3. Let x be undefined
5. Assign result.value to x
6. Return x
Lets consider for
example
foo6([0]);
Proprietary
Destructuring the ES2015 way Array
destructuring
1. Let iterator be CreateArrayIterator(a,value)
3. Let x be undefined
5. Assign result.value to x
Local
6. Return xallocations
a.length
a[index]
Proprietary
Destructuring the ES2015 way Array
destructuring
a.length and a[index] already optimizable
TurboFan Load Elimination and Escape Analysis to
eliminate non-escaping allocations
Plus some magic to kill the remaining overhead
(exception handling, iterator closing, etc.)
Only ~1.2x slower now in
Node 8
(Source: fhinkel.github.io/six-speed)
Proprietary
Spread calls and
Rest parameters
Proprietary
Spread calls and Rest parameters simple case
ES5:
Math.max.apply(Math,
[1,2,3]);
ES2015:
Math.max(...[1,2,3]);
Ca
37 : Star r8
args = %SpreadArguments([0], args) 39 : CallJSRuntime [153], r6-r8
43 : Star r5
45 : Mov r1, r4
return %Apply(Math.max, Math, args) 48 : CallJSRuntime [149], r2-r5
52 : Return
Proprietary
Spread calls and Rest parameters interesting
case 0 : CreateRestParameter
function max0(...args) { 1 : Star r0
return Math.max(0,...args); 3 : StackCheck
4 : LdaUndefined
} 5 : Star r2
7 : LdaGlobal [0], [2]
10 : Star r1
12 : LdaNamedProperty r1, [1], [4]
CallWithSpread(Math.max, Math, 0, args) 16 : Star r3
17 : LdaZero
18 : Star r2
19 : CallWithSpread r3, r1, r2-r2, r0
24 : Return
Node 8 Proprietary
Accidents
Proprietary
Proprietary
Proprietary
Disabled fast-path for
instanceof!
Proprietary
@@hasInstance vs instanceof
@@hasInstance made instanceof monkey-patchable
slow
fast
Proprietary
@@hasInstance vs instanceof
Avoid global protector
Proprietary
Proprietary
Approaching ES2017
Proprietary
Proprietary
Proprietary
Meaningful async/await
Performance test?
Proprietary
Proprietary
Questions?
Feedback!
Proprietary