From 7303f327950de4c28cca1c3928dc2d890918531f Mon Sep 17 00:00:00 2001 From: Nicholas Gates Date: Thu, 11 Dec 2025 09:39:18 +0000 Subject: [PATCH] Immutable session + registries Signed-off-by: Nicholas Gates --- vortex-session/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vortex-session/src/lib.rs b/vortex-session/src/lib.rs index f1e22a1a529..c53784173e0 100644 --- a/vortex-session/src/lib.rs +++ b/vortex-session/src/lib.rs @@ -88,6 +88,18 @@ impl SessionExt for VortexSession { /// Returns the scope variable of type `V`, or inserts a default one if it does not exist. fn get(&self) -> Ref<'_, V> { + // NOTE(ngates): we don't use `entry().or_insert_with_key()` here because the DashMap + // would immediately acquire an exclusive write lock. + if let Some(v) = self.0.get(&TypeId::of::()) { + return Ref(v.map(|v| { + (**v) + .as_any() + .downcast_ref::() + .vortex_expect("Type mismatch - this is a bug") + })); + } + + // If we get here, the value was not present, so we insert the default with a write lock. Ref(self .0 .entry(TypeId::of::())