Re:A tour of V8: object representation (2013)
by ryanlm on Saturday October 22, 2016 @11:53AM
(#12769162)
Yesterday I had to store integers as keys in a map. It's good to learn today that they are implicitly converted to strings. Yes I could have used an array, but that would of required me to know the max index I would suppose. Maybe in JavaScript I insert into the array at any index, but that doesn't seem usual to me, coming from a C background I'd allocate the max index + 1.
[ Parent
| on HN ]
Re:A tour of V8: object representation (2013)
by chrisseaton on Saturday October 22, 2016 @12:34PM
(#12769334)
I'm not a JavaScript expert but I believe most serious JavaScript implementations can represent sparse arrays, or arrays with holes in the range of indices, for this reason.
Re:A tour of V8: object representation (2013)
by BillinghamJ on Saturday October 22, 2016 @12:50PM
(#12769397)
Vaguely relevant/example: http://imgur.com/7Bf3hLZ
Re:A tour of V8: object representation (2013)
by fenomas on Saturday October 22, 2016 @01:57PM
(#12769745)
If performance is important, I believe it's still a fair bit faster to use a plain object as hash, rather than a Map. (If the keys are integers V8 may initially treat the object as an array, but it'll switch over to dictionary mode pretty quickly.)