Skip to content

Commit c930544

Browse files
perf: parking_lot
1 parent f670a8a commit c930544

4 files changed

Lines changed: 10 additions & 7 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crescendo/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ simple-tqdm = { version = "0.2.0", features = ["rayon"] }
2828
rand = "0.9.1"
2929
ratelimit = "0.10"
3030
clap = { version = "4.5", features = ["derive", "env"] }
31-
toml = "0.8"
31+
toml = "0.8"
32+
parking_lot = "0.12.4"

crescendo/src/tx_queue.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::collections::VecDeque;
22
use std::sync::atomic::{AtomicU64, Ordering};
3-
use std::sync::Mutex;
43
use std::time::Duration;
54

5+
use parking_lot::Mutex;
66
use ratelimit::Ratelimiter;
77
use thousands::Separable;
88

@@ -39,15 +39,15 @@ pub static TX_QUEUE: std::sync::LazyLock<TxQueue> = std::sync::LazyLock::new(TxQ
3939
impl TxQueue {
4040
pub fn push_tx(&self, tx: Vec<u8>) {
4141
self.total_added.fetch_add(1, Ordering::Relaxed);
42-
self.queue.lock().unwrap().push_back(tx);
42+
self.queue.lock().push_back(tx);
4343
}
4444

4545
pub fn queue_len(&self) -> usize {
46-
self.queue.lock().map(|q| q.len()).unwrap_or(0)
46+
self.queue.lock().len()
4747
}
4848

4949
pub async fn pop_at_most(&self, max_count: usize) -> Option<Vec<Vec<u8>>> {
50-
let mut queue = self.queue.lock().ok()?;
50+
let mut queue = self.queue.lock();
5151
let allowed = (0..queue.len().min(max_count)).take_while(|_| self.rate_limiter.try_wait().is_ok()).count();
5252
if allowed == 0 {
5353
return None;

crescendo/src/workers/tx_gen.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::collections::HashMap;
2-
use std::sync::{LazyLock, Mutex};
2+
use std::sync::LazyLock;
33
use std::time::Instant;
44

55
use alloy::network::TxSignerSync;
@@ -9,6 +9,7 @@ use alloy::sol_types::SolCall;
99
use alloy_consensus::{SignableTransaction, TxLegacy};
1010
use alloy_signer_local::coins_bip39::English;
1111
use alloy_signer_local::{MnemonicBuilder, PrivateKeySigner};
12+
use parking_lot::Mutex;
1213
use rand::Rng;
1314
use rayon::prelude::*;
1415
use thousands::Separable;
@@ -52,7 +53,7 @@ pub fn tx_gen_worker(_worker_id: u32) {
5253

5354
// Get and increment nonce atomically.
5455
let nonce = {
55-
let mut nonce_map = NONCE_MAP.lock().unwrap();
56+
let mut nonce_map = NONCE_MAP.lock();
5657
let current_nonce = *nonce_map.get(&account_index).unwrap();
5758
nonce_map.insert(account_index, current_nonce + 1);
5859
current_nonce

0 commit comments

Comments
 (0)