2 ms·
I had a somewhat similar discovery with V8 (JS VM): V8 allocates a whopping 64 bytes per empty object. {} But if you initialize it with a single property
by paulddraper 7y ago
I had a somewhat similar discovery with V8 (JS VM):
V8 allocates a whopping 64 bytes per empty object.
{}
But if you initialize it with a single property, the size shrinks to 40 bytes. [1]
{v8Hack: null}
I too was creating lots of object that would stay empty, but V8 (incorrectly) assumed I was going to change them later so it reserved some extra space. [2]
Unfortunately, there is no size hint like for Java's HashMap; the closest hint you can do is create your objects with dummy properties.
[1] https://stackoverflow.com/questions/59044239/why-do-empty-objects-take-more-memory-than-non-empty-ones https://stackoverflow.com/questions/59044239/why-do-empty-ob...
[2] https://www.mattzeunert.com/2017/03/29/v8-object-size.html https://www.mattzeunert.com/2017/03/29/v8-object-size.html