deepsize
deepsize copied to clipboard
Document differences from heapsize crate
The heapsize crate is a popular crate with many crates depending on it and lots of downloads. From the description of deepsize, I can't tell what it would do differently than heapsize. It would be worth calling this out in the readme as well as rustdocs.
@Aeledfyr
Note also that heapsize is now unmaintained, so it would be nice to be able to locate alternatives that may be better maintained.
@Aeledfyr In response to the release notes of 0.2.0, it seems the use case you intend to implement with deepsize is computing total dynamically allocated memory, to the exclusion of statically and automatically allocated memory?
Currently it considers all memory that is directly owned (using Rust's ownership semantics). That means that single owner allocating objects, ie. Box and most collections, are included in the size, while normal references (&T and &mut T) are not counted. Ownership gets ambiguous withe reference counted pointers since there is no single owner that controls the allocation. For Rc and Arc, this counts them once and then tracks them to avoid counting the same memory twice. (Weak variants are not counted).
What do you specifically mean by "statically and automatically allocated memory"?
The current system includes memory on the stack and owned memory on the heap; memory behind non owning references is not counted, so things like static arrays wouldn't be counted.
It's also important to note that this is only and can only be an estimation; without hooking into the allocator it isn't possible to have perfect accuracy in measurements, especially with things like HashMaps that don't expose their capacity or allocation sizes through their public APIs.
(I should probably write out a full justification of this in the docs, but I'm not entirely certain about all of it - there are other valid ways of dealing with reference counting or other shared memory)