Open
Description
Follow-up to #4736
One last follow-up: I installed d8 (debug v8) as suggested in the linked blog post.
$ ~/.jsvu/bin/v8-debug
V8 version 11.1.192
d8>
I was able to replicate their example:
const array = [1, 2, 3];
array[3] = 4.56;
$ ~/.jsvu/bin/v8-debug --trace-elements-transitions test.js
elements transition [PACKED_SMI_ELEMENTS -> PACKED_DOUBLE_ELEMENTS] in ~+15 at test.js:1 for 0x0e520010b461 <JSArray[3]> from 0x0e520025a3c1 <FixedArray[3]> to 0x0e520010b471 <FixedDoubleArray[22]>
But if I initialize elements one-by-one, then the initial state becomes HOLEY_SMI_ELEMENTS
.
const array = new Array(3);
array[0] = 1;
array[1] = 2;
array[2] = 3;
array[3] = 4.56;
elements transition [HOLEY_SMI_ELEMENTS -> HOLEY_DOUBLE_ELEMENTS] in ~+60 at test.js:1 for 0x02d60010b48d <JSArray[3]> from 0x02d60010b49d <FixedArray[3]> to 0x02d60010b4b1 <FixedDoubleArray[22]>
So unfortunately this is a sub-optimal initialization pattern on V8.
Originally posted by @armanbilge in #4736 (comment)