rpds
rpds copied to clipboard
Memory Usage for Debugging
What is a good way to get the current memory usage of a rpds structure? I'm looking for something like Servo's malloc_size_of. I can get the size of leaves but I'm missing the size of branches. Or is it trivial to calculate it? Any recommendation would be appreciated.
Hi @fredfortier. There's no simple way to get those numbers. I can imagine a custom allocator that keeps track of which functions allocate memory.
If you want to go a bit more intrusive and modify rpds you can traverse the tree of the data structure you want to inspect and sum all sizes together.
Keep in mind that most persistent data structures keep a fair amount of extra data, so I expect the memory overhead to be significant for most data structures.
Any simple formula I can use to compute an estimated size? I don't need precise measurements. If I can make some assumptions, like treat them all as uncolored binary search tree, while remaining in the ballpark, it might be good enough for me.
Which particular data structure are you trying to get the memory usage of?
These here: HashTrieMapSync, HashTrieSetSync, RedBlackTreeMapSync, RedBlackTreeSetSync, StackSync