JavaScript Array Performance, And Why It Matters
Arrays can present an unexpected performance bottleneck in JavaScript. Here I show that array performance is influenced by some surprising details of the array and how it’s used.
Arrays can present an unexpected performance bottleneck in JavaScript. Here I show that array performance is influenced by some surprising details of the array and how it’s used.
The JavaScript interpreters in the most popular browsers distinguish between sparse and dense arrays. Hence, you may get more “array-like” performance if you initialize an array before using it. But this trades memory for speed, so it may not always be the best choice.
It may well be that for better JavaScript performance, large arrays should be avoided where possible. That seems fairly clear in this case, where an already fast implementation of the missing String.trim() method was made even faster by using much smaller lookup table arrays.