I am not a javascript expert, I have not contributed to any javascript engines, so the following is just an assumption:
You have a lot to do in your pushMap function.
1. First, you expand var a to the desired size, apparently in a very inefficient way. length is just a property of the array, so either the base implementation has callbacks when the property is changed, or the base implementation can handle the length attribute, changing and moving with it the next time something is available in it.
2. Creating var b seems even more inefficient because you invoke a reflection type method to make b array of a specific length.
3. Then you basically call the foreach loop in a functional way, which is likely to be a bit slower than the while loop, due to the overhead of the inner function (closing, in my opinion, because it's JS)
You can get a more even result if you created var b in the same way you created var rv . Hope this helps. EDIT, which of course does not work in this situation, because the map only works with initialized array values. This means another reason this approach is slower (and the OP mentioned this in his question), you initialize the map twice, once with empty values ββand again with the values ββyou want.
source share