ECMAScript 2015 (ES6) • ECMA-262 Edition 6, released in June 2015 • Features: arrow functions / classes / promise / let / const / template literals / generators / proper tail calls etc… • You can try some of them with recent implementations or compilers (e.g. Babel, Traceur)
ECMAScript 2016 (ES7) • ECMA-262 Edition 7, released in June 2016 !!!!!!!!!""""""""" • Minor update from ECMAScript 2015 • exponentiation operator ** • Array.prototype.includes
Let’s try it n Result Time [msec] 1,000 Infinity 0.36 10,000 Infinity 1.65 100,000 Maximum call stack size exceeded. 14655.18 049&M$BQJUBO4BGBSJ .BD#PPL1SP &BSMZ $PSFJ6 ???
Call Stack • Call stack is used when function is called • Includes arguments, return address, etc… • Size is limited → We reached that limit when we call fact(100,000) ộ n = 97 n = 98 n = 99 n = 100 ộ
Proper Tail Calls (PTC) • If a tail call meets some conditions… • strict mode, normal function or arrow function, etc… • ECMAScript 2015 requires that a call in tail position will reuse the caller’s stack space!! • Differs from tail call optimization
Benefit of PTC • Unbounded number of consecutive tail calls • Reduce stack size / memory footprint • Performance improvements • Less processing when returning value • But maybe slower than for-loop → Better performance with beautiful code!
Conclusion • Proper Tail Call is one of the best feature in ES2015 • Natural, beautiful & high-performance code! • Let’s try it with following implementations • Safari Technology Preview • WebKit Nightly Build • XS6