From 678f51a7453ccebd1863ab8f87fc0ddb0d29f596 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Thu, 22 May 2025 11:26:17 +0200 Subject: [PATCH] Short-circuit `block-on` if same thread (#862) * Short-circuit `block_on` if same thread * Avoid acquiring the lock --- src/runtime.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/runtime.rs b/src/runtime.rs index 84e1bae9..3eb80442 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -172,8 +172,13 @@ impl Runtime { other_id: ThreadId, query_mutex_guard: QueryMutexGuard, ) -> BlockResult { - let dg = self.dependency_graph.lock(); let thread_id = thread::current().id(); + // Cycle in the same thread. + if thread_id == other_id { + return BlockResult::Cycle; + } + + let dg = self.dependency_graph.lock(); if dg.depends_on(other_id, thread_id) { return BlockResult::Cycle;