From 0b6e27934d6bdb3e91f116574ae1a754eb24ae0c Mon Sep 17 00:00:00 2001 From: Basil Milanich Date: Mon, 6 Apr 2026 13:48:53 -0500 Subject: [PATCH] ConcurrentHashMap: add insert_or_assign to replace erase+emplace The cudaGraphCurrentLaunch cache update was acquiring the write lock twice (once for erase, once for emplace). Wrapping std::unordered_map::insert_or_assign under a single write lock lets the caller do it in one operation. Co-Authored-By: Claude Sonnet 4.6 --- public/tracy/TracyCUDA.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/public/tracy/TracyCUDA.hpp b/public/tracy/TracyCUDA.hpp index d0dac51f..d540aa96 100644 --- a/public/tracy/TracyCUDA.hpp +++ b/public/tracy/TracyCUDA.hpp @@ -360,6 +360,11 @@ struct ConcurrentHashMap { auto lock = acquire_write_lock(); return mapping.erase(key); } + auto insert_or_assign(TKey key, TValue value) { + ZoneNamed(insert_or_assign, instrument); + auto lock = acquire_write_lock(); + return mapping.insert_or_assign(std::move(key), std::move(value)); + } }; #if TRACY_CUDA_ENABLE_CUDA_CALL_STATS @@ -917,9 +922,7 @@ namespace tracy return false; } } else if (graphId != 0) { - auto& cache = PersistentState::Get().cudaGraphCurrentLaunch; - cache.erase(graphId); - cache.emplace(graphId, apiCallInfo); + PersistentState::Get().cudaGraphCurrentLaunch.insert_or_assign(graphId, apiCallInfo); } return true; }