This post is my notes from this excellent article on complexity by Greek Cryptography/Blockchains PhD candidate, Dionysis "dionyziz" Zindros. I hig...
For further actions, you may consider blocking this person and/or reporting abuse
How is
slice
so much faster?Most of JavaScript's functions on objects (Array objects included) are using some sort of a hashing algorithm to iterate over their properties [Citation needed]. It's not just a for loop as in your example.
And WOW, creating the array at the correct size really makes a huge difference:
Less than 3x slowdown over
.slice()
while still allowing you to modify each value!Yeah, in theory. But V8 does a lot of runtime optimization. A for loop incrementing by 1 over specifically a continuous array surely doesn't actually do hashmap lookups with the integer at every iteration. I'm sure that no kind of SIMD is taking place, but when it sees that there are no break/continue branches, surely it at least iterates over the values directly?