Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Remove calls to heapsize #10432

Merged
merged 29 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bcaa9eb
Use mem utils crate from parity common
cheme Dec 6, 2018
1776a32
Use derive macro for clarity (even when derive impl return 0).
cheme Dec 7, 2018
3a0d78d
Setting jemalloc as default allocator for parity client.
cheme Dec 7, 2018
10e30b7
Revert jmalloc default: need to update memorydb crate to stop using
cheme Dec 7, 2018
a159dcd
update to new module name (alloc -> allocators), test estimate.
cheme Dec 10, 2018
24131fd
latest test
cheme Dec 27, 2018
9157b74
update renamings
cheme Jan 2, 2019
1668aec
test with jemalloc
cheme Jan 9, 2019
c521348
Plug onto github branch
cheme Jan 9, 2019
e04af62
Merge attempt for branch 'master' into rem_heapsize
cheme Jan 9, 2019
5d0b165
Update to reorg.
cheme Jan 9, 2019
c3d23fc
Merge branch 'master' into rem_heapsize
cheme Jan 14, 2019
3f0ed81
switch to deprecate branch of memorydb
cheme Jan 14, 2019
f21ca1b
Merge branch 'master' into rem_heapsize
cheme Jan 25, 2019
7c56348
latest version of parity-util-mem
cheme Jan 25, 2019
15317ca
Merge branch 'master' into rem_heapsize, and update to use current git
cheme Feb 27, 2019
59ab2d1
Do not switch test ...
cheme Feb 28, 2019
32cafaa
In progress version switch,
cheme Jun 3, 2019
a571878
in progress (need merge with memorydb update)
cheme Jun 6, 2019
d44a8f9
Branch ready to rebase (synch with latest trie changes done).
cheme Jun 6, 2019
86ef606
Merge branch 'master' into rem_heapsize
cheme Jun 7, 2019
449e23a
Remove 'estimate_heapsize' mode.
cheme Jun 7, 2019
527ff6b
fix comment related to perf ignored and bitset heapsize impl.
cheme Jun 9, 2019
2653106
Remove patch in favor of published crates.
cheme Jun 13, 2019
118df73
Merge branch 'rem_heapsize' of github.com:cheme/parity-ethereum into …
cheme Jun 13, 2019
82521c4
0.12.3 trie crate were yanked, using 0.12.4
cheme Jun 18, 2019
f683856
Merge branch 'master' into rem_heapsize
cheme Jun 19, 2019
d3a5bed
Refactor parity_util_mem import (crate alias are kept only for macro …
cheme Jun 19, 2019
620a0c1
Missing parity_util_mem direct usage.
cheme Jun 19, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 131 additions & 74 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ ethcore-secretstore = { path = "secret-store", optional = true }

registrar = { path = "util/registrar" }

parity-util-mem = { version = "0.1", features = ["jemalloc-global", "estimate-heapsize"] }

[build-dependencies]
rustc_version = "0.2"

Expand Down Expand Up @@ -138,8 +140,10 @@ members = [
"util/triehash-ethereum",
"util/keccak-hasher",
"util/patricia-trie-ethereum",
"util/fastmap"
"util/fastmap",
]

[patch.crates-io]
heapsize = { git = "https://github.com/cheme/heapsize.git", branch = "ec-macfix" }
memory-db = { git = "https://github.com/cheme/trie", branch = "deprecate_heapsize" }
trie-db = { git = "https://github.com/cheme/trie", branch = "deprecate_heapsize" }
hash-db = { git = "https://github.com/cheme/trie", branch = "deprecate_heapsize" }
2 changes: 1 addition & 1 deletion accounts/ethkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1" }
ethereum-types = "0.4"
lazy_static = "1.0"
log = "0.4"
memzero = { path = "../../util/memzero" }
parity-util-mem = "0.1"
parity-wordlist = "1.2"
quick-error = "1.2.2"
rand = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion accounts/ethkey/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern crate byteorder;
extern crate edit_distance;
extern crate parity_crypto;
extern crate ethereum_types;
extern crate memzero;
extern crate parity_util_mem as mem;
extern crate parity_wordlist;
#[macro_use]
extern crate quick_error;
Expand Down
2 changes: 1 addition & 1 deletion accounts/ethkey/src/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc_hex::ToHex;
use secp256k1::constants::{SECRET_KEY_SIZE as SECP256K1_SECRET_KEY_SIZE};
use secp256k1::key;
use ethereum_types::H256;
use memzero::Memzero;
use mem::Memzero;
use {Error, SECP256K1};

#[derive(Clone, PartialEq, Eq)]
Expand Down
8 changes: 4 additions & 4 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ ethereum-types = "0.4"
ethjson = { path = "../json" }
ethkey = { path = "../accounts/ethkey" }
evm = { path = "evm" }
hash-db = "0.11.0"
heapsize = "0.4"
hash-db = "0.12.2"
parity-util-mem = "0.1"
itertools = "0.5"
journaldb = { path = "../util/journaldb" }
keccak-hash = "0.1"
Expand All @@ -45,15 +45,15 @@ log = "0.4"
lru-cache = "0.1"
macros = { path = "../util/macros" }
memory-cache = { path = "../util/memory-cache" }
memory-db = "0.11.0"
memory-db = "0.12.3"
num = { version = "0.1", default-features = false, features = ["bigint"] }
num_cpus = "1.2"
parity-bytes = "0.1"
parity-crypto = "0.3.0"
parity-machine = { path = "../machine" }
parity-snappy = "0.1"
parking_lot = "0.7"
trie-db = "0.11.0"
trie-db = "0.12.2"
patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" }
rand = "0.4"
rayon = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion ethcore/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ blooms-db = { path = "../../util/blooms-db" }
common-types = { path = "../types" }
ethcore-db = { path = "../db" }
ethereum-types = "0.4"
heapsize = "0.4"
parity-util-mem = "0.1"
itertools = "0.5"
kvdb = "0.1"
log = "0.4"
Expand Down
24 changes: 13 additions & 11 deletions ethcore/blockchain/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use ethcore_db::cache_manager::CacheManager;
use ethcore_db::keys::{BlockReceipts, BlockDetails, TransactionAddress, EPOCH_KEY_PREFIX, EpochTransitions};
use ethcore_db::{self as db, Writable, Readable, CacheUpdatePolicy};
use ethereum_types::{H256, Bloom, BloomRef, U256};
use heapsize::HeapSizeOf;
use util_mem::{MallocSizeOf, allocators::new_malloc_size_ops};
use itertools::Itertools;
use kvdb::{DBTransaction, KeyValueDB};
use log::{trace, warn, info};
Expand Down Expand Up @@ -1482,11 +1482,12 @@ impl BlockChain {

/// Get current cache size.
pub fn cache_size(&self) -> CacheSize {
let mut ops = new_malloc_size_ops();
CacheSize {
blocks: self.block_headers.read().heap_size_of_children() + self.block_bodies.read().heap_size_of_children(),
block_details: self.block_details.read().heap_size_of_children(),
transaction_addresses: self.transaction_addresses.read().heap_size_of_children(),
block_receipts: self.block_receipts.read().heap_size_of_children(),
blocks: self.block_headers.size_of(&mut ops) + self.block_bodies.size_of(&mut ops),
block_details: self.block_details.size_of(&mut ops),
transaction_addresses: self.transaction_addresses.size_of(&mut ops),
block_receipts: self.block_receipts.size_of(&mut ops),
}
}

Expand Down Expand Up @@ -1521,12 +1522,13 @@ impl BlockChain {
transaction_addresses.shrink_to_fit();
block_receipts.shrink_to_fit();

block_headers.heap_size_of_children() +
block_bodies.heap_size_of_children() +
block_details.heap_size_of_children() +
block_hashes.heap_size_of_children() +
transaction_addresses.heap_size_of_children() +
block_receipts.heap_size_of_children()
let mut ops = new_malloc_size_ops();
block_headers.size_of(&mut ops) +
block_bodies.size_of(&mut ops) +
block_details.size_of(&mut ops) +
block_hashes.size_of(&mut ops) +
transaction_addresses.size_of(&mut ops) +
block_receipts.size_of(&mut ops)
});
}

Expand Down
3 changes: 3 additions & 0 deletions ethcore/blockchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

#![warn(missing_docs)]

extern crate parity_util_mem as util_mem;
extern crate parity_util_mem as malloc_size_of;

mod best_block;
mod block_info;
mod blockchain;
Expand Down
2 changes: 1 addition & 1 deletion ethcore/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ edition = "2018"
[dependencies]
common-types = { path = "../types" }
ethereum-types = "0.4"
heapsize = "0.4"
kvdb = "0.1"
parity-util-mem = "0.1"
parking_lot = "0.7"
rlp = { version = "0.3.0", features = ["ethereum"] }
rlp_derive = { path = "../../util/rlp-derive" }
24 changes: 4 additions & 20 deletions ethcore/db/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use common_types::BlockNumber;
use common_types::engines::epoch::Transition as EpochTransition;
use common_types::receipt::Receipt;
use ethereum_types::{H256, H264, U256};
use heapsize::HeapSizeOf;
use mem::MallocSizeOf;
use kvdb::PREFIX_LEN as DB_PREFIX_LEN;
use rlp;
use rlp_derive::{RlpEncodableWrapper, RlpDecodableWrapper, RlpEncodable, RlpDecodable};
Expand Down Expand Up @@ -144,7 +144,7 @@ impl Key<EpochTransitions> for u64 {
}

/// Familial details concerning a block
#[derive(Debug, Clone)]
#[derive(Debug, Clone, MallocSizeOf)]
pub struct BlockDetails {
/// Block number
pub number: BlockNumber,
Expand Down Expand Up @@ -199,27 +199,17 @@ impl rlp::Decodable for BlockDetails {
}
}

impl HeapSizeOf for BlockDetails {
fn heap_size_of_children(&self) -> usize {
self.children.heap_size_of_children()
}
}

/// Represents address of certain transaction within block
#[derive(Debug, PartialEq, Clone, RlpEncodable, RlpDecodable)]
#[derive(Debug, PartialEq, Clone, RlpEncodable, RlpDecodable, MallocSizeOf)]
pub struct TransactionAddress {
/// Block hash
pub block_hash: H256,
/// Transaction index within the block
pub index: usize
}

impl HeapSizeOf for TransactionAddress {
fn heap_size_of_children(&self) -> usize { 0 }
}

/// Contains all block receipts.
#[derive(Clone, RlpEncodableWrapper, RlpDecodableWrapper)]
#[derive(Clone, RlpEncodableWrapper, RlpDecodableWrapper, MallocSizeOf)]
pub struct BlockReceipts {
/// Block receipts
pub receipts: Vec<Receipt>,
Expand All @@ -234,12 +224,6 @@ impl BlockReceipts {
}
}

impl HeapSizeOf for BlockReceipts {
fn heap_size_of_children(&self) -> usize {
self.receipts.heap_size_of_children()
}
}

/// Candidate transitions to an epoch with specific number.
#[derive(Clone, RlpEncodable, RlpDecodable)]
pub struct EpochTransitions {
Expand Down
3 changes: 3 additions & 0 deletions ethcore/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

#![warn(missing_docs)]

extern crate parity_util_mem as mem;
extern crate parity_util_mem as malloc_size_of;

mod db;

pub mod keys;
Expand Down
2 changes: 1 addition & 1 deletion ethcore/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
bit-set = "0.4"
parity-bytes = "0.1"
ethereum-types = "0.4"
heapsize = "0.4"
parity-util-mem = "0.1"
lazy_static = "1.0"
log = "0.4"
vm = { path = "../vm" }
Expand Down
2 changes: 1 addition & 1 deletion ethcore/evm/benches/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern crate criterion;
extern crate bit_set;
extern crate ethereum_types;
extern crate parking_lot;
extern crate heapsize;
extern crate parity_util_mem as mem;
extern crate vm;
extern crate evm;
extern crate keccak_hash as hash;
Expand Down
6 changes: 3 additions & 3 deletions ethcore/evm/src/interpreter/shared_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use std::sync::Arc;
use hash::KECCAK_EMPTY;
use heapsize::HeapSizeOf;
use mem::{MallocSizeOf, MallocSizeOfOps};
use ethereum_types::H256;
use parking_lot::Mutex;
use memory_cache::MemoryLruCache;
Expand All @@ -28,8 +28,8 @@ const DEFAULT_CACHE_SIZE: usize = 4 * 1024 * 1024;
// stub for a HeapSizeOf implementation.
dvdplm marked this conversation as resolved.
Show resolved Hide resolved
struct Bits(Arc<BitSet>);

impl HeapSizeOf for Bits {
fn heap_size_of_children(&self) -> usize {
impl MallocSizeOf for Bits {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
// dealing in bits here
self.0.capacity() * 8
}
Expand Down
2 changes: 1 addition & 1 deletion ethcore/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
extern crate bit_set;
extern crate ethereum_types;
extern crate parking_lot;
extern crate heapsize;
extern crate parity_util_mem as mem;
extern crate vm;
extern crate keccak_hash as hash;
extern crate memory_cache;
Expand Down
8 changes: 4 additions & 4 deletions ethcore/light/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ ethcore = { path = ".."}
ethcore-db = { path = "../db" }
ethcore-blockchain = { path = "../blockchain" }
ethereum-types = "0.4"
memory-db = "0.11.0"
trie-db = "0.11.0"
memory-db = "0.12.3"
trie-db = "0.12.2"
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
ethcore-network = { path = "../../util/network" }
ethcore-io = { path = "../../util/io" }
hash-db = "0.11.0"
heapsize = "0.4"
hash-db = "0.12.2"
parity-util-mem = "0.1"
vm = { path = "../vm" }
fastmap = { path = "../../util/fastmap" }
failsafe = { version = "0.3.0", default-features = false, features = ["parking_lot_mutex"] }
Expand Down
10 changes: 6 additions & 4 deletions ethcore/light/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
//! vector of all gas prices from a recent range of blocks.

use std::time::{Instant, Duration};
use mem::{MallocSizeOf, MallocSizeOfOps, MallocSizeOfExt};

use common_types::encoded;
use common_types::BlockNumber;
use common_types::receipt::Receipt;
use ethereum_types::{H256, U256};
use heapsize::HeapSizeOf;
use memory_cache::MemoryLruCache;
use stats::Corpus;

Expand Down Expand Up @@ -157,12 +157,14 @@ impl Cache {

/// Get the memory used.
pub fn mem_used(&self) -> usize {
self.heap_size_of_children()
self.malloc_size_of()
}
}

impl HeapSizeOf for Cache {
fn heap_size_of_children(&self) -> usize {

// TODO this is fast method: should feature gate an exhaustive implementation
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please file an issue and add a ref to this comment.

impl MallocSizeOf for Cache {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
self.headers.current_size()
+ self.canon_hashes.current_size()
+ self.bodies.current_size()
Expand Down
19 changes: 10 additions & 9 deletions ethcore/light/src/client/header_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use ethcore::engines::epoch::{Transition as EpochTransition, PendingTransition a
use ethcore::error::{Error, EthcoreResult, ErrorKind as EthcoreErrorKind, BlockError};
use ethcore::spec::{Spec, SpecHardcodedSync};
use ethereum_types::{H256, H264, U256};
use heapsize::HeapSizeOf;
use mem::{MallocSizeOf, MallocSizeOfOps};
use kvdb::{DBTransaction, KeyValueDB};
use parking_lot::{Mutex, RwLock};
use fastmap::H256FastMap;
Expand Down Expand Up @@ -95,8 +95,8 @@ struct Entry {
canonical_hash: H256,
}

impl HeapSizeOf for Entry {
fn heap_size_of_children(&self) -> usize {
impl MallocSizeOf for Entry {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
if self.candidates.spilled() {
self.candidates.capacity() * ::std::mem::size_of::<Candidate>()
} else {
Expand Down Expand Up @@ -196,14 +196,21 @@ pub enum HardcodedSync {
Deny,
}

#[derive(MallocSizeOf)]
/// Header chain. See module docs for more details.
pub struct HeaderChain {
#[ignore_malloc_size_of = "perf"]
dvdplm marked this conversation as resolved.
Show resolved Hide resolved
genesis_header: encoded::Header, // special-case the genesis.
candidates: RwLock<BTreeMap<u64, Entry>>,
#[ignore_malloc_size_of = "perf"]
best_block: RwLock<BlockDescriptor>,
#[ignore_malloc_size_of = "perf"]
live_epoch_proofs: RwLock<H256FastMap<EpochTransition>>,
#[ignore_malloc_size_of = "perf"]
db: Arc<KeyValueDB>,
#[ignore_malloc_size_of = "perf"]
col: Option<u32>,
#[ignore_malloc_size_of = "perf"]
cache: Arc<Mutex<Cache>>,
}

Expand Down Expand Up @@ -832,12 +839,6 @@ impl HeaderChain {
}
}

impl HeapSizeOf for HeaderChain {
fn heap_size_of_children(&self) -> usize {
self.candidates.read().heap_size_of_children()
}
}

/// Iterator over a block's ancestry.
pub struct AncestryIter<'a> {
next: Option<encoded::Header>,
Expand Down
4 changes: 2 additions & 2 deletions ethcore/light/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ impl<T: ChainDataFetcher> Client<T> {

/// Get blockchain mem usage in bytes.
pub fn chain_mem_used(&self) -> usize {
use heapsize::HeapSizeOf;
use mem::MallocSizeOfExt;

self.chain.heap_size_of_children()
self.chain.malloc_size_of()
}

/// Get a handle to the verification engine.
Expand Down
3 changes: 2 additions & 1 deletion ethcore/light/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ extern crate parity_bytes as bytes;
extern crate ethereum_types;
extern crate ethcore;
extern crate hash_db;
extern crate heapsize;
extern crate parity_util_mem as malloc_size_of;
extern crate parity_util_mem as mem;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is confusing, it will require devs to come here to look. I think I'd prefer explicit paths here.

extern crate failsafe;
extern crate futures;
extern crate itertools;
Expand Down
Loading