mirror of
https://github.com/wolfpld/tracy.git
synced 2026-10-16 13:55:27 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user