Optimize audit_pool key hashing as well. Use a const for starting capacity for tx related lists.

This commit is contained in:
junderw
2023-06-24 23:42:18 -07:00
committed by Mononaut
parent ded2352cf8
commit 3c652bdcbc
2 changed files with 22 additions and 8 deletions

View File

@@ -11,6 +11,14 @@ mod thread_transaction;
mod utils;
use thread_transaction::ThreadTransaction;
/// This is the starting capacity for HashMap/Vec/etc. that deal with transactions.
/// HashMap doubles capacity when it hits it, so 2048 is a decent tradeoff between
/// not wasting too much memory when it's below this, and allowing for less re-allocations
/// by virtue of starting with such a large capacity.
///
/// Note: This doesn't *have* to be a power of 2. (uwu)
const STARTING_CAPACITY: usize = 2048;
type ThreadTransactionsMap = HashMap<u32, ThreadTransaction, U32HasherState>;
#[napi]
@@ -25,7 +33,7 @@ impl GbtGenerator {
pub fn new() -> Self {
Self {
thread_transactions: Arc::new(Mutex::new(HashMap::with_capacity_and_hasher(
2048,
STARTING_CAPACITY,
U32HasherState,
))),
}