I keep seeing dictionary mode described as V8's slow mode for object properties. What kinds of changes trigger it, and what does it actually mean for inline caching and performance?
What puts a V8 object into dictionary mode, and how much does it matter?
Answers
V8 can store named properties in a fast representation where objects with the same shape share layout information. An inline cache can use that shape to help find a property efficiently. In dictionary mode, named properties are stored in a dictionary instead, so accessing them can require a dictionary lookup.
That doesn't mean every access becomes uncached or that the whole program suddenly gets slow. The effect depends on the access pattern, how often it runs, and what optimizations the V8 version can apply. Also, indexed elements are handled separately from named properties, so don't assume a change to one tells you everything about the other.
Reply to this answer
Property deletion is one thing to investigate, especially when objects are repeatedly changed after creation. Adding lots of properties or using property definitions can also lead to different representations. But there isn't a reliable rule that every delete, or every object above one fixed property count, must go dictionary mode.
The operation, object layout, and V8 version can all matter. Treat a list of observed triggers as test results for a particular build, not a permanent specification.
Reply to this answer
If this matters to your code, make a small test for the exact operations you use and run it on each Node version you support. V8 has internal debugging helpers that can be exposed with a flag to inspect fast properties, but those helpers aren't a stable JavaScript API.
Test ordinary assignment separately from Object.defineProperty, and record where a transition first occurs. Then benchmark the actual hot path too. A representation change by itself doesn't tell you whether the difference will be meaningful for your workload.
Reply to this answer
Dictionary mode isn't necessarily a one-way trip. V8 has paths that can make some objects fast again, including cases involving prototypes. I wouldn't count on a hot loop automatically converting an object back, though. The conditions are implementation details and need checking on the version you're running.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Tavquelo-4n:
Does deleting the last property behave differently from deleting one in the middle?
4y!ferrulepulley_728:
It can. That's a useful distinction to test rather than grouping every deletion together, but the result can change between V8 versions.