Skip to content

Commit 95c9516

Browse files
committed
perf: snapshot workspace cache in try_from() to minimize lock hold (PR #460)
1 parent 66b67fa commit 95c9516

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

crates/pet-hatch/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,14 @@ impl Locator for Hatch {
188188
// unrelated virtualenvwrapper / `venv` env in the same directory
189189
// would be misclassified as Hatch-managed.
190190
if classification.is_none() {
191-
let cache = self
191+
// Snapshot the cache (cheap `Arc` clones) under the lock and
192+
// release it before iterating, to keep `configure()` from being
193+
// blocked by callers on the hot identification path.
194+
let cache: Vec<Arc<WorkspaceEntry>> = self
192195
.workspace_virtual_dirs
193196
.lock()
194-
.expect("workspace_virtual_dirs mutex poisoned");
197+
.expect("workspace_virtual_dirs mutex poisoned")
198+
.clone();
195199
'workspaces: for entry in cache.iter() {
196200
for virtual_dir in &entry.virtual_dirs {
197201
if prefix_is_directly_under(&prefix, virtual_dir) {

0 commit comments

Comments
 (0)