Skip to content
Open
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
35 changes: 21 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,49 @@ name = "concread"
path = "src/lib.rs"

[features]
default = ["asynch", "foldhash", "ebr", "maps", "arcache-is-hashtrie"]
default = ["std", "asynch", "foldhash", "ebr", "maps", "arcache-is-hashtrie"]

# Features to add/remove contents.
ahash = ["dep:ahash"]
foldhash = ["dep:foldhash"]

arcache = ["maps", "lru", "crossbeam-queue"]
asynch = ["tokio"]
ebr = ["crossbeam-epoch"]
maps = ["crossbeam-utils", "smallvec"]
asynch = ["dep:tokio", "std"]
ebr = ["std"]
maps = ["dep:crossbeam-utils", "smallvec"]
tcache = []
std = ["ahash/std", "ahash/runtime-rng", "crossbeam-epoch/std", "crossbeam-queue/std", "crossbeam-utils/std", "tracing/std", "dep:parking_lot", "smallvec/write"]
no_std = ["crossbeam-epoch/alloc", "crossbeam-queue/alloc", "serde/alloc", "ahash"]


# Internal features for tweaking some align/perf behaviours.
dhat-heap = ["dep:dhat"]
skinny = []
hashtrie_skinny = []

arcache-is-hashmap = ["arcache"]
arcache-is-hashtrie = ["arcache"]
simd_support = []


[dependencies]
ahash = { version = "0.8", optional = true }
foldhash = { version = "0.1.5", optional = true }
crossbeam-utils = { version = "0.8.21", optional = true }
crossbeam-epoch = { version = "0.9.11", optional = true }
crossbeam-queue = { version = "0.3.12", optional = true }
ahash = { version = "0.8", default-features = false, optional = true}
foldhash = { version = "0.1.5",default-features = false, optional = true }
crossbeam-utils = { version = "0.8.21", optional = true, default-features = false, features = []}
crossbeam-epoch = { version = "0.9.11", optional = true, default-features = false, features = [] }
crossbeam-queue = { version = "0.3.12", optional = true, default-features = false, features = [] }
dhat = { version = "0.3.3", optional = true }
lru = { version = "0.13", optional = true }
lru = { version = "0.16", optional = true }
serde = { version = "1.0", optional = true }
smallvec = { version = "1.14", optional = true }
sptr = "0.3"
tokio = { version = "1", features = ["sync"], optional = true }
tracing = "0.1"
tracing = {version = "0.1", default-features = false}
lock_api = "0.4"
parking_lot = {version = "0.12.3", optional = true }
hashbrown = {version = "0.15.2", default-features = false}
cfg-if = "1.0.0"

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
criterion = { version = "0.6.0", features = ["html_reports"] }
rand = "0.9"
tracing-subscriber = { version = "0.3", features = [
"env-filter",
Expand All @@ -71,6 +77,7 @@ function_name = "0.3"
serde_json = "1"
tokio = { version = "1", features = ["rt", "macros"] }
proptest = "1.0.0"
spin = {version = "0.10.0", default-features = false, features = ["lock_api", "spin_mutex", "rwlock"]}

[[bench]]
name = "hashmap_benchmark"
Expand Down
14 changes: 7 additions & 7 deletions benches/arccache.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use function_name::named;
use rand::distributions::uniform::SampleUniform;
use rand::{thread_rng, Rng};
use rand::{rng, Rng};
use std::collections::HashMap;
use std::fmt::Debug;
use std::hash::Hash;
Expand All @@ -11,7 +11,7 @@ use std::thread;
use std::time::{Duration, Instant};
// use uuid::Uuid;

use concread::arcache::{ARCache, ARCacheBuilder};
use concread::arcache::{ARCacheRaw, ARCacheBuilder};
use concread::threadcache::ThreadLocal;
use criterion::measurement::{Measurement, ValueFormatter};

Expand Down Expand Up @@ -54,8 +54,8 @@ where
fn next(&self) -> T {
match self {
AccessPattern::Random(min, max) => {
let mut rng = thread_rng();
rng.gen_range(min.clone()..max.clone())
let mut rng = rng();
rng.random_range(min.clone()..max.clone())
}
}
}
Expand Down Expand Up @@ -261,7 +261,7 @@ where
}

fn multi_thread_worker<K, V>(
arc: Arc<ARCache<K, V>>,
arc: Arc<ARCacheRaw<K, V>>,
backing_set: Arc<HashMap<K, V>>,
backing_set_delay: Option<Duration>,
access_pattern: AccessPattern<K>,
Expand Down Expand Up @@ -311,7 +311,7 @@ where
csize = 1;
}

let arc: Arc<ARCache<K, V>> = Arc::new(
let arc: Arc<ARCacheRaw<K, V>> = Arc::new(
ARCacheBuilder::new()
.set_size(csize, 0)
.set_watermark(0)
Expand Down Expand Up @@ -420,7 +420,7 @@ where
csize = 1;
}

let arc: ARCache<K, V> = ARCacheBuilder::new()
let arc: ARCacheRaw<K, V> = ARCacheBuilder::new()
.set_size(csize, 0)
.set_watermark(0)
.set_reader_quiesce(false)
Expand Down
34 changes: 18 additions & 16 deletions benches/hashmap_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ extern crate criterion;
extern crate rand;

use concread::hashmap::*;
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
use rand::{thread_rng, Rng};
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use rand::{rng, Rng};

use std::hint::black_box;

// ranges of counts for different benchmarks (MINs are inclusive, MAXes exclusive):
const INSERT_COUNT_MIN: usize = 120;
Expand Down Expand Up @@ -168,7 +170,7 @@ criterion_main!(insert, remove, search);
fn insert_vec<V: Clone + Sync + Send + 'static>(
map: &mut HashMap<u32, V>,
list: Vec<(u32, V)>,
) -> HashMapWriteTxn<u32, V> {
) -> HashMapWriteTxn<u32, V, parking_lot::RawMutex> {
let mut write_txn = map.write();
for (key, val) in list.into_iter() {
write_txn.insert(key, val);
Expand All @@ -179,7 +181,7 @@ fn insert_vec<V: Clone + Sync + Send + 'static>(
fn remove_vec<'a, V: Clone + Sync + Send + 'static>(
map: &'a mut HashMap<u32, V>,
list: &Vec<u32>,
) -> HashMapWriteTxn<'a, u32, V> {
) -> HashMapWriteTxn<'a, u32, V, parking_lot::RawMutex> {
let mut write_txn = map.write();
for i in list.iter() {
write_txn.remove(i);
Expand Down Expand Up @@ -242,12 +244,12 @@ struct Struct {
}

fn prepare_insert<V: Clone + Sync + Send + 'static>(value: V) -> (HashMap<u32, V>, Vec<(u32, V)>) {
let mut rng = thread_rng();
let count = rng.gen_range(INSERT_COUNT_MIN..INSERT_COUNT_MAX);
let mut rng = rng();
let count = rng.random_range(INSERT_COUNT_MIN..INSERT_COUNT_MAX);
let mut list = Vec::with_capacity(count);
for _ in 0..count {
list.push((
rng.gen_range(0..INSERT_COUNT_MAX << 8) as u32,
rng.random_range(0..INSERT_COUNT_MAX << 8) as u32,
value.clone(),
));
}
Expand All @@ -256,9 +258,9 @@ fn prepare_insert<V: Clone + Sync + Send + 'static>(value: V) -> (HashMap<u32, V

/// Prepares a remove benchmark with values in the HashMap being clones of the 'value' parameter
fn prepare_remove<V: Clone + Sync + Send + 'static>(value: V) -> (HashMap<u32, V>, Vec<u32>) {
let mut rng = thread_rng();
let insert_count = rng.gen_range(INSERT_COUNT_FOR_REMOVE_MIN..INSERT_COUNT_FOR_REMOVE_MAX);
let remove_count = rng.gen_range(REMOVE_COUNT_MIN..REMOVE_COUNT_MAX);
let mut rng = rng();
let insert_count = rng.random_range(INSERT_COUNT_FOR_REMOVE_MIN..INSERT_COUNT_FOR_REMOVE_MAX);
let remove_count = rng.random_range(REMOVE_COUNT_MIN..REMOVE_COUNT_MAX);
let map = HashMap::new();
let mut write_txn = map.write();
for i in random_order(insert_count, insert_count).iter() {
Expand All @@ -271,10 +273,10 @@ fn prepare_remove<V: Clone + Sync + Send + 'static>(value: V) -> (HashMap<u32, V
}

fn prepare_search<V: Clone + Sync + Send + 'static>(value: V) -> (HashMap<u32, V>, Vec<u32>) {
let mut rng = thread_rng();
let insert_count = rng.gen_range(INSERT_COUNT_FOR_SEARCH_MIN..INSERT_COUNT_FOR_SEARCH_MAX);
let mut rng = rng();
let insert_count = rng.random_range(INSERT_COUNT_FOR_SEARCH_MIN..INSERT_COUNT_FOR_SEARCH_MAX);
let search_limit = insert_count * SEARCH_SIZE_NUMERATOR / SEARCH_SIZE_DENOMINATOR;
let search_count = rng.gen_range(SEARCH_COUNT_MIN..SEARCH_COUNT_MAX);
let search_count = rng.random_range(SEARCH_COUNT_MIN..SEARCH_COUNT_MAX);

// Create a HashMap with elements 0 through insert_count(-1)
let map = HashMap::new();
Expand All @@ -287,20 +289,20 @@ fn prepare_search<V: Clone + Sync + Send + 'static>(value: V) -> (HashMap<u32, V
// Choose 'search_count' numbers from [0,search_limit) randomly to be searched in the created map.
let mut list = Vec::with_capacity(search_count);
for _ in 0..search_count {
list.push(rng.gen_range(0..search_limit as u32));
list.push(rng.random_range(0..search_limit as u32));
}
(map, list)
}

/// Returns a Vec of n elements from the range [0,up_to) in random order without repetition
fn random_order(up_to: usize, n: usize) -> Vec<u32> {
let mut rng = thread_rng();
let mut rng = rng();
let mut order = Vec::with_capacity(n);
let mut generated = vec![false; up_to];
let mut remaining = n;
let mut remaining_elems = up_to;
while remaining > 0 {
let mut r = rng.gen_range(0..remaining_elems);
let mut r = rng.random_range(0..remaining_elems);
// find the r-th yet nongenerated number:
for i in 0..up_to {
if generated[i] {
Expand Down
11 changes: 9 additions & 2 deletions src/arcache/ll.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
#[cfg(feature = "std")]
use std::boxed::Box;

use std::fmt::Debug;
use std::marker::PhantomData;
use std::mem::MaybeUninit;
Expand Down Expand Up @@ -309,10 +314,12 @@ where
(*next).prev = prev;
(*prev).next = next;
// Null things for paranoia.
if cfg!(test) || cfg!(debug_assertions) {

cfg_if::cfg_if! { if #[cfg(any(test, debug_assertions))]
{
(*n.inner).prev = ptr::null_mut();
(*n.inner).next = ptr::null_mut();
}
}}
// (*n).tag = 0;
}

Expand Down
Loading
Loading