ES6 in Node v6 - Redfin Real Estate News

ES6 in Node v6

by
Updated on October 5th, 2020

Node 6 dropped today, and it includes V8 v5, which implements 96% of the ES6 standard, as measured by the kangax compatibility table.  At this point, you might consider only transpiling ES7 features like import / export and async / await.  But what are the performance implications of switching from Babel to V8 native?  I went through each of the ES6 features listed on the V8 blog released between 4.5 (the version of V8 in 4.0.0) and 5 (the version of V8 in 6.0.0).

You can see the test harness and tests on our github page. In general, it seems to be a wash as to whether to use Babel or Node native from a performance standpoint; it may be worthwhile to turn off your Babel transforms to make your transpiled server-side javascript more readable.  More detailed results follow:

Spread Operator

Math.max(-1, …[-1, 5, 11], 3) // 11

Testing spread
Node results: min 827.29 ms max: 855.65 ms mean: 844.019 ms
Babel results: min 833.51 ms max: 861.93 ms mean: 847.01 ms
node is 0.4% faster

Rest operator

const [x, …y] = [‘a’, ‘b’, ‘c’]; // x=’a’; y=[‘b’, ‘c’]

Testing rest
Node results: min 1230.66 ms max: 1296.05 ms mean: 1255.2350000000001 ms
Babel results: min 1230.19 ms max: 1292.25 ms mean: 1252.0760000000002 ms
babel is 0.3% faster

Array.prototype.includes

[“apple”, “banana”, “cherry”].includes(“apple”) // true

Testing array-includes
Node results: min 865.39 ms max: 887.29 ms mean: 877.9619999999999 ms
Babel results: min 870.71 ms max: 906.53 ms mean: 888.872 ms
node is 1.2% faster

toPrimitive and isConcatSpreadable

({ [Symbol.toPrimitive](hint){return 12} }) + 12 // 24

Testing to-primitive
Node results: min 1034.85 ms max: 1146.37 ms mean: 1093.8049999999998 ms
Babel results: min 1030.12 ms max: 1104.63 ms mean: 1074.011 ms
babel is 1.8% faster

Symbol.toStringTag

({[Symbol.toStringTag]: ‘Foo’}.toString()) // ‘[object Foo]’

Testing to-string-tag
Node results: min 715.22 ms max: 1157.05 ms mean: 933.577 ms
Babel results: min 710.71 ms max: 1168.74 ms mean: 896.434 ms
babel is 4% faster

Default parameters

function sublist(list, start = 0, end = list.length) { … }

Testing default-parameters
Node results: min 719.47 ms max: 1165.03 ms mean: 899.086 ms
Babel results: min 716.88 ms max: 741.43 ms mean: 729.324 ms
babel is 18.9% faster

Proxies & Reflect

(new Proxy({}, { get() { return 123 } })).bar // 123

Testing proxy
Node results: min 715.15 ms max: 1186.28 ms mean: 1063.049 ms
Babel results: min 726.51 ms max: 1180.13 ms mean: 1108.535 ms
node is 4.1% faster

Destructuring

let [x, y, …r] = [1, 2, 3, 4]; // x=1, y=2, r=[3,4]

Testing destructuring
Node results: min 845.47 ms max: 873.15 ms mean: 859.4529999999999 ms
Babel results: min 830.17 ms max: 867.17 ms mean: 852.933 ms
babel is 0.8% faster

Unicode (emoji) regex

/?{2}/u.test(‘??’); //true

Testing unicode-regex
Node results: min 1013.32 ms max: 1065.64 ms mean: 1048.119 ms
Babel results: min 1037.11 ms max: 1078.2 ms mean: 1057.127 ms
node is 0.9% faster

Run on a MacBook Pro, 2.5 GHz Intel Core i7 w/ 16 GB of RAM

Also in node v6.0.0

let, const and class outside of strict mode

reduced gc jank

better math.random()

Avatar

Doug Wade

I'm a software developer at Redfin on the Platforms team. I'm a cyclist, soccer hooligan, and beer enthusiast.

Email Doug

Leave a Comment

Your email address will not be published. Required fields are marked *

Be the first to see the latest real estate news:

  • This field is for validation purposes and should be left unchanged.

By submitting your email you agree to Redfin’s Terms of Use and Privacy Policy

Scroll to Top