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.
July 22 2009 by
Dan Breslau in
Web |
Sometimes the best way to solve a problem is to make it no longer be a problem. This was the case with a problem that I’d created — and have now fixed — in my version of SyntaxHighlighter.
SyntaxHighlighter now preserves whitespace. Kind of. It’s not pure WYSIWYG, but it’s YCAGWYWBIYTSYJMFYGWYN. It’s good enough that we can stop using Flash to access the clipboard.