Diggsey / ijson

More efficient alternative to `serde_json::Value` which saves memory by interning primitive values and using tagged pointers.
Apache License 2.0
127 stars 14 forks source link

Recommended way to get the memory usage of IValue #16

Closed MeirShpilraien closed 2 years ago

MeirShpilraien commented 2 years ago

Hey, I would like to know (at runtime), for a given IValue, what is the memory usage it consumes. Any recommended way to do it? Is it something that makes sense to add to the API? Thanks.

Diggsey commented 2 years ago

This is not really possible as some memory is intentionally shared between different IValues (such as via IString which is interned).

The way I do this for the comparison script is that I install a custom allocator which tracks memory usage for the whole application. You could try a similar thing.

If you just want a very rough approximation, you could recursively iterate the IValue and give each type a "cost" function, but this isn't something I want to add to the crate.