Hacker News new | ask | show | jobs
by bufferoverflow 2056 days ago
I'm pretty sure destructuring is still slow as hell. Like if you want to clone an array, arr.slice(0) is 3x faster than [...arr]
1 comments

I mean yeah... You're telling the engine to do 2 different things there that just may have the same end-result.

The results diverge specifically when your array contains empty items, which will be converted to items containing undefined with the latter expression.

The JS engine would need a specific optimization for cases where:

- The expression is equivalent to arr.slice(0)

- The iterator being de-structured is a vanilla array

- The array doesn't contain any empty items

Of course your code will be faster when all that's required is just a shallow copy.