Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Get rid of parity-util-mem dependency #12658

@ordian

Description

@ordian

Originally reported in #12657 (comment)

Steps:

  1. Identify all the usage: https://cs.github.com/paritytech/substrate?q=malloc_size
    At the moment it seems there are two
  1. Replace the usage by an estimation. It could be something like
    /// 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;
    }
    or more brittle
  • 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 alongside NonCanonicalOverlay that is tracking size on every insertion/deletion to its field pinned_insertions or 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.

Metadata

Metadata

Assignees

Labels

I7-refactorCode needs refactoring.Z2-mediumCan 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.

Type

No type
No fields configured for issues without a type.

Projects

Status

done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions