Skip to content

Commit

Permalink
Merge pull request #154 from input-output-hk/imhamt-box-optimisation
Browse files Browse the repository at this point in the history
Optimise HAMT inner representation to use Box instead of Vec
  • Loading branch information
vincenthz committed Nov 21, 2019
2 parents 611b26f + fdadcee commit d889b61
Show file tree
Hide file tree
Showing 10 changed files with 421 additions and 500 deletions.
8 changes: 8 additions & 0 deletions imhamt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ license = "MIT OR Apache-2.0"
quickcheck = "0.8"
quickcheck_macros = "0.8"

[target.'cfg(unix)'.dev-dependencies]
jemalloc-ctl = "*"
jemallocator = "*"

[features]
default = []
with-bench = []
optimized-node = []

[[example]]
name = "memdump"
path = "examples/memdump/main.rs"
14 changes: 14 additions & 0 deletions imhamt/examples/memdump/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#[cfg(unix)]
mod unix;

#[cfg(unix)]
use unix::run;

#[cfg(not(unix))]
fn run() {
println!("example not supported on this platform")
}

fn main() {
run()
}
51 changes: 51 additions & 0 deletions imhamt/examples/memdump/unix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
extern crate imhamt;
extern crate jemalloc_ctl;
extern crate jemallocator;

use jemalloc_ctl::{epoch, stats};
use std::collections::hash_map::DefaultHasher;
use std::thread;
use std::time::Duration;

#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

use imhamt::Hamt;

fn statprint() {
let allocated = stats::allocated::read().unwrap();
let resident = stats::resident::read().unwrap();
println!("{} bytes allocated/{} bytes resident", allocated, resident);
}

pub fn run() {
let mut h: Hamt<DefaultHasher, u32, u32> = Hamt::new();

println!("adding 100000 entries");

for i in 0..100000 {
h = h.insert(i, i).unwrap();
}

let mut h2 = h.clone();

epoch::advance().unwrap();

statprint();
thread::sleep(Duration::from_secs(10));

println!("adding 100000 entries");

for i in 100000..200000 {
h2 = h2.insert(i, i).unwrap();
}

epoch::advance().unwrap();

statprint();
thread::sleep(Duration::from_secs(10));

epoch::advance().unwrap();

statprint();
}
2 changes: 1 addition & 1 deletion imhamt/src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl SmallBitmap {

#[inline]
/// Create a new bitmap with 1 element set
pub fn once(b: LevelIndex) -> Self {
pub const fn once(b: LevelIndex) -> Self {
SmallBitmap(b.mask())
}

Expand Down

0 comments on commit d889b61

Please sign in to comment.