-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
We need to report in runtime the memory each IValue takes.
What is the best way to calculate its overhead, even ignoring the IString intern?
I tried to sum it calc it this way
fn size(v: &IValue) -> Result<usize, Error> {
let res = size_of::<IValue>()
+ match v.type_() {
ValueType::Null | ValueType::Bool | ValueType::Number => 0,
ValueType::String => v.as_string().unwrap().len(),
ValueType::Array => v
.as_array()
.unwrap()
.into_iter()
.map(|v| size(v).unwrap())
.sum(),
ValueType::Object => v
.as_object()
.unwrap()
.into_iter()
.map(|(s, v)| s.len() + size(v).unwrap())
.sum(),
};
Ok(res)
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels