Say you have a change in an object that triggers a change in the size of the underlying array or data structure storing the hash values.
var x = { a: 1, b: 2, c: 3 }
// trigger a resize theoretically
x.d = 4
x.e = 5
x.f = 6
Say the underlying array for the hash looked like this in v8
[ 1, 3, 2, null, null ]
It created some extra space initially. But it wasn't quite enough so then it had to grow. There are two options.
- It grows leaving the original values in there current place.
- It grows and rehashes, moving the values to arbitrary new places.
So it would look like:
// (1) 1, 3, 2 stay where they are
[ 1, 3, 2, 6, 4, 5, null, null, null, null ]
// (2) 1, 3, 2 are moved
[ 6, 2, 5, 3, 4, 1, null, null, null, null ]
Wondering what v8 does in this situation. Also wondering what the heuristics are for the resizing (does it double the array size when it outgrows, etc.).