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 <noreply@anthropic.com>
This commit is contained in:
Basil Milanich
2026-04-06 13:48:53 -05:00
parent d9a1cc06c1
commit 0b6e27934d

View File

@@ -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;
}