Skip to content

Add a top level function to parity-util-mem#298

Merged
ordian merged 4 commits into
masterfrom
nv-mem-utils-5
Jan 2, 2020
Merged

Add a top level function to parity-util-mem#298
ordian merged 4 commits into
masterfrom
nv-mem-utils-5

Conversation

@NikVolf
Copy link
Copy Markdown
Contributor

@NikVolf NikVolf commented Dec 31, 2019

  • to avoid importing traits in the namespace
  • also this seems the only way to query heap size of Arc<dyn SomeTrait: MallocSizeOf>, if user needs to

Copy link
Copy Markdown
Collaborator

@cheme cheme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, minus the CI error (I did not know we checked the format).

Comment thread parity-util-mem/src/lib.rs Outdated
Comment thread parity-util-mem/src/lib.rs Outdated
Comment thread parity-util-mem/src/lib.rs Outdated
trait Augmented : MallocSizeOf { }
impl Augmented for Vec<u8> { }
let val: Arc<dyn Augmented> = Arc::new(vec![0u8; 1024]);
assert!(malloc_size(&*val) > 1000);
Copy link
Copy Markdown
Contributor

@ordian ordian Jan 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it actually use Arc in calculation? Dereference implies that it doesn't?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it does not, it uses those of the dereferenced trait.

This is for cases when you know that Arc is the primary reference

MallocSizeOf is not defined for Arc<T: ?Sized>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, measuring MallocSizeOf for an Arc is tricky, but I wonder why a type is required to be Sized for Arc (in MallocUnconditionalShallowSizeOf), but not for Box.

Anyway, my point was that using Arc in tests causes a bit of confusion, we can use a trait object here directly, something like

let val = vec![0u8; 1024];
let val_ref: &dyn Augmented = &val as _; 
assert!(malloc_size(val_ref) > 1000);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also wondering about those constraints.

About the test, I only wanted to show how to measure Arc in the test, also to ensure the exactly Arc<dyn Trait> can be measured -- it is a higher-level requirement, so hope we can have it as it is.

NikVolf and others added 3 commits January 1, 2020 14:03
Co-Authored-By: cheme <emericchevalier.pro@gmail.com>
Co-Authored-By: cheme <emericchevalier.pro@gmail.com>
Copy link
Copy Markdown
Contributor

@ordian ordian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding support for Arc<dyn Trait> seems nontrivial, let's merge it as is.

@ordian ordian merged commit ab5d566 into master Jan 2, 2020
@ordian ordian deleted the nv-mem-utils-5 branch January 2, 2020 12:48
dvdplm added a commit that referenced this pull request Jan 14, 2020
* master: (27 commits)
  update parity-util-mem (#309)
  Update features and feature dependencies (#307)
  Use proper memory queries to rocksdb (#308)
  Draft version updates and changelog (#299)
  Use custom error type for `from_hex` (#305)
  Fix typo. (#303)
  kvdb: remove KeyValueDBHandler (#304)
  extract common kvdb tests into a crate (#301)
  Expose to_hex and from_hex from impl-serde (#302)
  Add a top level function to parity-util-mem (#298)
  I/O statistic for key-value databases (#294)
  use for_tuples (#300)
  Add memory extensions for LRUCache, hashbrown (#293)
  Add memory stats for kvdb-s (#292)
  Provide #[derive(MallocSizeOf)] that is actually working (#291)
  Move and extend impls for locking primitives (#290)
  Update uint README (#288)
  Update README.md (#287)
  [ci]: remove feature flags in virtual workspace (#289)
  Prepare releases (#286)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants