This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Get rid of parity-util-mem dependency #12658
Copy link
Copy link
Closed
Labels
I7-refactorCode needs refactoring.Code needs refactoring.Z2-mediumCan be fixed by a coder with good Rust knowledge but little knowledge of the codebase.Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase.Z6-mentorAn easy task where a mentor is available. Please indicate in the issue who the mentor could be.An easy task where a mentor is available. Please indicate in the issue who the mentor could be.
Description
Originally reported in #12657 (comment)
Steps:
- Identify all the usage: https://cs.github.com/paritytech/substrate?q=malloc_size
At the moment it seems there are two
- substrate (informational only):
substrate/client/state-db/src/lib.rs
Lines 500 to 506 in cbb48e5
fn memory_info(&self) -> StateDbMemoryInfo { StateDbMemoryInfo { non_canonical: MemorySize::from_bytes(malloc_size(&self.non_canonical)), pruning: self.pruning.as_ref().map(|p| MemorySize::from_bytes(malloc_size(&p))), pinned: MemorySize::from_bytes(malloc_size(&self.pinned)), } } - polkadot: https://github.com/paritytech/polkadot/blob/a70d12ae1da07167bb33c5fce6f6f4f5ab511fff/node/core/runtime-api/src/cache.rs#L54-L58
- Replace the usage by an estimation. It could be something like or more brittle
substrate/client/db/src/storage_cache.rs
Lines 62 to 72 in 20b5aac
/// Internal trait similar to `heapsize` but using /// a simply estimation. /// /// This should not be made public, it is implementation /// detail trait. If it need to become public please /// consider using `malloc_size_of`. trait EstimateSize { /// Return a size estimation of additional size needed /// to cache this struct (in bytes). fn estimate_size(&self) -> usize; }
- For each collection, you can estimate size by
.capacity() * mem::size_of::<T>(). - The only problematic case is nested data-structures, like pinned_insertions: HashMap<BlockHash, (Vec, u32)>,. Here the value size is variable.
A workaround could be adding a struct alongsideNonCanonicalOverlaythat is tracking size on every insertion/deletion to its fieldpinned_insertionsor simply assuming max size.
Once the usage is replaced, to get rid of the dependency completely, we'd need to remove it from a number of crates in https://github.com/paritytech/trie and https://github.com/paritytech/parity-common.
mustermeiszerascjones, jsdw and mustermeiszermustermeiszer
Metadata
Metadata
Assignees
Labels
I7-refactorCode needs refactoring.Code needs refactoring.Z2-mediumCan be fixed by a coder with good Rust knowledge but little knowledge of the codebase.Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase.Z6-mentorAn easy task where a mentor is available. Please indicate in the issue who the mentor could be.An easy task where a mentor is available. Please indicate in the issue who the mentor could be.
Type
Projects
Status
done