Member-only story
What is the ES6 spread operator and why you shouldn’t use it
Important note: This article is no longer accurate, these performance issues are fixed in the recent versions of V8.
JavaScript introduced a spread operator in ES6, which helps you write shorter and nicer code. I started using this operator everywhere I could immediately after learning about it, because why not? It’s the new syntax that was introduced, it’s the future, it simplifies many things, it makes your code shorter while maintaining readability, it’s perfect.
Recently I started working on a new project named Clio. It’s a new and modern programming language made for the cloud. It’s functional, and it compiles to JavaScript. While writing the lexer, the parser and the code generator for this new language, I encountered numerous difficulties and problems caused by JavaScript performance and limitations.
Clio is a functional language and it should be fast, so after writing each new part of its code, I did several performance checks and benchmarks. After coding the exception and the traceback system of Clio, I noticed a huge performance drop in my tests. After investigating the issue, I realized it is caused simply by using the spread operator in my code.
Let’s analyze some of the most common uses of the spread operator.