From 5353435d5c52a0cd71fb6b0791f9f811e8f4f357 Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Mon, 16 Mar 2026 17:23:21 +0000 Subject: [PATCH] gpui: Fix hash collision panics in ProfilingCollector (#51683) (cherry-pick to preview) (#51690) Cherry-pick of #51683 to preview ---- Release Notes: - N/A *or* Added/Fixed/Improved ... Co-authored-by: Lukas Wirth --- crates/gpui/src/profiler.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/gpui/src/profiler.rs b/crates/gpui/src/profiler.rs index ccbc86e3fe35a095b2de9de159286250a24d7a05..dc6e9a6600f5c172050fd30cfed181ac7ed81ec4 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, + cursors: HashMap, } 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;