Search code examples
javascriptcachinglimitinlinev8

What is the limit on the number of "fast", "inlinable" properties in v8 object?


Question for v8 experts.

As we know, if the "shape" of the object does not change, v8 stores the object properties in a special array, and access them by index, which results in very fast access. I may be wrong on the details.

As described in this blog post from 2018, the size limit for this array is 1022.

Is this information still correct? Perhaps there were some improvements on this recently?

Thank you!


Solution

  • While I don't know how that blog post arrived at that number, the current value of kMaxNumberOfDescriptors is 1020, and the maximum number of entries in a PropertiesArray is 1023. Not sure why there's a difference, also not sure it matters... In a quick test, it seems that 1020 is the effective maximum, but maybe I'm overlooking some way to make an object grow to 1022 properties without transitioning to dictionary mode.

    Meta-observation: object handling in a JS engine is waaaay more complicated than just having a single limit. See e.g. TooManyFastProperties() for some of the fun.

    if the "shape" of the object does not change, v8 stores the object properties in a special array

    This is an incorrect simplification. In particular, adding properties (which constitutes a shape change) does not usually trigger a transition to dictionary mode.