Skip to content

Commit 4bd926c

Browse files
lutterclaude
andcommitted
store: Replace std::sync::RwLock with parking_lot::RwLock in store_events
Replace std::sync::RwLock with parking_lot::RwLock in the SubscriptionManager to reduce lock contention. parking_lot's RwLock is faster for short-held locks due to efficient spinning before parking, which helps reduce tokio threadpool contention. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 121b41e commit 4bd926c

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

store/postgres/src/store_events.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use graph::futures01::Stream;
22
use graph::futures03::compat::Stream01CompatExt;
33
use graph::futures03::stream::StreamExt;
44
use graph::futures03::TryStreamExt;
5-
use std::sync::{atomic::Ordering, Arc, RwLock};
5+
use std::sync::{atomic::Ordering, Arc};
6+
7+
use graph::parking_lot::RwLock;
68
use std::{collections::HashMap, sync::atomic::AtomicUsize};
79
use tokio::sync::mpsc::{channel, Sender};
810
use tokio_stream::wrappers::ReceiverStream;
@@ -127,7 +129,7 @@ impl SubscriptionManager {
127129

128130
// Send to `subscriptions`.
129131
{
130-
let senders = subscriptions.read().unwrap().clone();
132+
let senders = subscriptions.read().clone();
131133

132134
// Write change to all matching subscription streams; remove subscriptions
133135
// whose receiving end has been dropped
@@ -138,7 +140,7 @@ impl SubscriptionManager {
138140
"Failed to send store event to subscriber {}: {}", id, e
139141
);
140142
// Receiver was dropped
141-
subscriptions.write().unwrap().remove(&id);
143+
subscriptions.write().remove(&id);
142144
}
143145
}
144146
}
@@ -187,7 +189,7 @@ impl SubscriptionManager {
187189

188190
// Cleanup `subscriptions`.
189191
{
190-
let mut subscriptions = subscriptions.write().unwrap();
192+
let mut subscriptions = subscriptions.write();
191193

192194
// Obtain IDs of subscriptions whose receiving end has gone
193195
let stale_ids = subscriptions
@@ -218,7 +220,7 @@ impl SubscriptionManagerTrait for SubscriptionManager {
218220
let (sender, receiver) = channel(100);
219221

220222
// Add the new subscription
221-
self.subscriptions.write().unwrap().insert(id, sender);
223+
self.subscriptions.write().insert(id, sender);
222224

223225
// Return the subscription ID and entity change stream
224226
ReceiverStream::new(receiver)

0 commit comments

Comments
 (0)