From 1248a55d32f5fc64c7a26cd606fdf4c2908ce09c Mon Sep 17 00:00:00 2001 From: Sebastian Ullrich Date: Fri, 7 Feb 2025 11:14:35 +0100 Subject: [PATCH] perf: avoid taking mutex on already-resolved promises (#6984) --- src/runtime/object.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/runtime/object.cpp b/src/runtime/object.cpp index 636d7a1440..82e427abc6 100644 --- a/src/runtime/object.cpp +++ b/src/runtime/object.cpp @@ -842,6 +842,10 @@ public: } void resolve(lean_task_object * t, object * v) { + if (t->m_value) { + dec(v); + return; + } unique_lock lock(m_mutex); if (t->m_value) { lock.unlock(); // `dec(v)` could lead to `deactivate_task` trying to take the lock