The post https://v8.dev/blog/fast-properties mentions there are three kinds of properties. How do I find out which one a property is?
I am expecting answers with a v8 native syntax function or a devtool feature.
(V8 developer here.)
Whether an object has dictionary-mode properties is a per-object (not per-property) decision. The alternative state is to have "fast" properties, which typically means a mix of in-object and out-of-object properties.
Any build of V8 running with --allow-natives-syntax
can use %HasFastProperties(obj)
to tell whether an object has "fast" properties (returned value is true
) or dictionary properties (false
).
To see how many in-object properties a "fast"-mode object has, you need a Debug build, and use %DebugPrint(obj)
.
To the best of my knowledge, DevTools does not expose this information. (Which is fine IMHO, as you shouldn't need to care about this, aside from curiosity.)
Side note: I think that "fast" and "slow" are very misleading descriptions, because they sound way too much like "good case" and "bad case", when in fact they have different strengths and weaknesses. Objects that track their precise property layout using their hidden class are fast at reading/writing the values of existing properties, but exceedingly slow at adding/removing properties. Objects that use a dictionary for their properties are a little slower at reading/writing property values, but much faster at adding/removing properties. So depending on your app's use case, you sometimes want the one and sometimes the other, and aside from pathological cases the engine is also pretty good at switching to the one or the other, and there's no object state that's clearly better than the other. (And if you know you'll be adding and removing many properties, using a Map
is going to give you better performance than using plain objects.)