Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui: Fix hash collision panics in ProfilingCollector (#51683)

Lukas Wirth44c73a8753db
diff --git a/crates/gpui/src/profiler.rs b/crates/gpui/src/profiler.rs
index ccbc86e3fe3..dc6e9a6600f 100644
--- a/crates/gpui/src/profiler.rs
+++ b/crates/gpui/src/profiler.rs
@@ -169,7 +169,7 @@ pub struct ThreadTimingsDelta {
#[doc(hidden)]
pub struct ProfilingCollector {
startup_time: Instant,
- cursors: HashMap<u64, u64>,
+ cursors: HashMap<ThreadId, u64>,
}
impl ProfilingCollector {
@@ -195,7 +195,7 @@ impl ProfilingCollector {
thread.thread_id.hash(&mut hasher);
let hashed_id = hasher.finish();
- let prev_cursor = self.cursors.get(&hashed_id).copied().unwrap_or(0);
+ let prev_cursor = self.cursors.get(&thread.thread_id).copied().unwrap_or(0);
let buffer_len = thread.timings.len() as u64;
let buffer_start = thread.total_pushed.saturating_sub(buffer_len);
@@ -205,7 +205,7 @@ impl ProfilingCollector {
thread.timings.as_slice()
} else {
let skip = (prev_cursor - buffer_start) as usize;
- &thread.timings[skip..]
+ &thread.timings[skip.min(thread.timings.len())..]
};
// Don't emit the last entry if it's still in-progress (end: None).
@@ -215,12 +215,12 @@ impl ProfilingCollector {
}
let cursor_advance = if incomplete_at_end {
- thread.total_pushed - 1
+ thread.total_pushed.saturating_sub(1)
} else {
thread.total_pushed
};
- self.cursors.insert(hashed_id, cursor_advance);
+ self.cursors.insert(thread.thread_id, cursor_advance);
if slice.is_empty() {
continue;