Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise HAMT inner representation to use Box instead of Vec #154

Merged
merged 7 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading