Skip to content

Commit

Permalink
Increase the num segments of the waiters hash table from 16 to 64
Browse files Browse the repository at this point in the history
This will reduce the chance of issue #34 occurring.
  • Loading branch information
tatsuya6502 committed May 20, 2022
1 parent cde3a9c commit 14dcdd8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/future/value_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::{
};
use triomphe::Arc as TrioArc;

const WAITER_MAP_NUM_SEGMENTS: usize = 64;

type ErrorObject = Arc<dyn Any + Send + Sync + 'static>;

pub(crate) enum InitResult<V, E> {
Expand Down Expand Up @@ -102,7 +104,10 @@ where
{
pub(crate) fn with_hasher(hasher: S) -> Self {
Self {
waiters: crate::cht::SegmentedHashMap::with_num_segments_and_hasher(16, hasher),
waiters: crate::cht::SegmentedHashMap::with_num_segments_and_hasher(
WAITER_MAP_NUM_SEGMENTS,
hasher,
),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/sync/base_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,9 @@ where
let initial_capacity = initial_capacity
.map(|cap| cap + WRITE_LOG_SIZE * 4)
.unwrap_or_default();
let num_segments = 64;
const NUM_SEGMENTS: usize = 64;
let cache = crate::cht::SegmentedHashMap::with_num_segments_capacity_and_hasher(
num_segments,
NUM_SEGMENTS,
initial_capacity,
build_hasher.clone(),
);
Expand Down
7 changes: 6 additions & 1 deletion src/sync/value_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::{
};
use triomphe::Arc as TrioArc;

const WAITER_MAP_NUM_SEGMENTS: usize = 64;

type ErrorObject = Arc<dyn Any + Send + Sync + 'static>;
type WaiterValue<V> = Option<Result<V, ErrorObject>>;
type Waiter<V> = TrioArc<RwLock<WaiterValue<V>>>;
Expand All @@ -32,7 +34,10 @@ where
{
pub(crate) fn with_hasher(hasher: S) -> Self {
Self {
waiters: crate::cht::SegmentedHashMap::with_num_segments_and_hasher(16, hasher),
waiters: crate::cht::SegmentedHashMap::with_num_segments_and_hasher(
WAITER_MAP_NUM_SEGMENTS,
hasher,
),
}
}

Expand Down

0 comments on commit 14dcdd8

Please sign in to comment.