mirror of https://github.com/xacrimon/dashmap
feat: memoize default shard amount (#222)
Use once_cell crate to memoize the value. This doesn't add any new dependencies, as once_cell was already a subdependency. Additionally it was merged into std in nighlty and awaiting stabilization.
This commit is contained in:
parent
030671060f
commit
9deeb37ccb
|
@ -23,6 +23,7 @@ hashbrown = { version = "0.12.0", default-features = false }
|
||||||
serde = { version = "1.0.136", optional = true, features = ["derive"] }
|
serde = { version = "1.0.136", optional = true, features = ["derive"] }
|
||||||
cfg-if = "1.0.0"
|
cfg-if = "1.0.0"
|
||||||
rayon = { version = "1.5.2", optional = true }
|
rayon = { version = "1.5.2", optional = true }
|
||||||
|
once_cell = "1.13.0"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
features = ["rayon", "raw-api", "serde"]
|
features = ["rayon", "raw-api", "serde"]
|
||||||
|
|
|
@ -35,6 +35,7 @@ use iter::{Iter, IterMut, OwningIter};
|
||||||
use mapref::entry::{Entry, OccupiedEntry, VacantEntry};
|
use mapref::entry::{Entry, OccupiedEntry, VacantEntry};
|
||||||
use mapref::multiple::RefMulti;
|
use mapref::multiple::RefMulti;
|
||||||
use mapref::one::{Ref, RefMut};
|
use mapref::one::{Ref, RefMut};
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
pub use read_only::ReadOnlyView;
|
pub use read_only::ReadOnlyView;
|
||||||
pub use set::DashSet;
|
pub use set::DashSet;
|
||||||
use std::collections::hash_map::RandomState;
|
use std::collections::hash_map::RandomState;
|
||||||
|
@ -60,7 +61,10 @@ pub(crate) type HashMap<K, V, S> = hashbrown::HashMap<K, SharedValue<V>, S>;
|
||||||
pub struct TryReserveError {}
|
pub struct TryReserveError {}
|
||||||
|
|
||||||
fn default_shard_amount() -> usize {
|
fn default_shard_amount() -> usize {
|
||||||
(std::thread::available_parallelism().map_or(1, usize::from) * 4).next_power_of_two()
|
static DEFAULT_SHARD_AMOUNT: OnceCell<usize> = OnceCell::new();
|
||||||
|
*DEFAULT_SHARD_AMOUNT.get_or_init(|| {
|
||||||
|
(std::thread::available_parallelism().map_or(1, usize::from) * 4).next_power_of_two()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ncb(shard_amount: usize) -> usize {
|
fn ncb(shard_amount: usize) -> usize {
|
||||||
|
|
Loading…
Reference in New Issue