Skip to content

Commit ba0e97a

Browse files
authored
Avoid taking write lock on VortexSession::get (#5688)
I was seeing increasing contention from #5662 The alternate and more invasive fix is in #5685 , but we should decide if we want to allowing registering plugins after "startup", and what that means for language bindings that use a global static session object. Signed-off-by: Nicholas Gates <[email protected]>
1 parent f8870ae commit ba0e97a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

vortex-session/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ impl SessionExt for VortexSession {
8888

8989
/// Returns the scope variable of type `V`, or inserts a default one if it does not exist.
9090
fn get<V: SessionVar + Default>(&self) -> Ref<'_, V> {
91+
// NOTE(ngates): we don't use `entry().or_insert_with_key()` here because the DashMap
92+
// would immediately acquire an exclusive write lock.
93+
if let Some(v) = self.0.get(&TypeId::of::<V>()) {
94+
return Ref(v.map(|v| {
95+
(**v)
96+
.as_any()
97+
.downcast_ref::<V>()
98+
.vortex_expect("Type mismatch - this is a bug")
99+
}));
100+
}
101+
102+
// If we get here, the value was not present, so we insert the default with a write lock.
91103
Ref(self
92104
.0
93105
.entry(TypeId::of::<V>())

0 commit comments

Comments
 (0)