While it is a small object, it is created every time the function runs.
This seems like one relatively simple and obvious optimisation for any javascript engine developer. It would be foolish that with all the work and money spent on chrome, firefox or any other browser, this one case was left unoptimised. Does the author think that javascript engines are written by neophytes? I did go and wrote a small test case for this and found no real performance difference between declaring the array outside the function or inside it (node).
This article smells terribly of premature optimisation, and worse yet, doesn't measure whether it's faster or not. It succumbs to one of the worst sins in optimisation - doing it prematurely and on a whim. Please don't be like the author and write optimisations only based on preconceptions and gut feelings.
Results on Chrome especially were surprising. The class static method was the fastest. By far. By more than an order of magnitude. Of the others, the original "unoptimized" version was fastest.
FF and Edge behaved more like how we would naively expect. The original "unoptimized" version was slightly slowest, the others roughly on par with each other.
119
u/PickledPokute Oct 09 '18 edited Oct 09 '18
This seems like one relatively simple and obvious optimisation for any javascript engine developer. It would be foolish that with all the work and money spent on chrome, firefox or any other browser, this one case was left unoptimised. Does the author think that javascript engines are written by neophytes? I did go and wrote a small test case for this and found no real performance difference between declaring the array outside the function or inside it (node).
This article smells terribly of premature optimisation, and worse yet, doesn't measure whether it's faster or not. It succumbs to one of the worst sins in optimisation - doing it prematurely and on a whim. Please don't be like the author and write optimisations only based on preconceptions and gut feelings.