2 ms·
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]
by bufferoverflow 6y 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]
- chmod775 6y agoI 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.