Skip to content

Commit ed82233

Browse files
authored
gpui: Box Window instances (#40733)
We very frequently move this in and out of the windows slot map on `update_window_id` calls (and we call this a lot!). This alone showed up as `memmove`s at roughly 1% perf in Instruments when scrolling a buffer which makes sense, `Window` itself is 4kb in size. The fix is simple, just box the `Window` instances, moving a pointer is cheap in comparison. Release Notes: - N/A *or* Added/Fixed/Improved ...
1 parent ec0efc9 commit ed82233

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

crates/gpui/src/app.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ pub struct App {
553553
pub(crate) entities: EntityMap,
554554
pub(crate) window_update_stack: Vec<WindowId>,
555555
pub(crate) new_entity_observers: SubscriberSet<TypeId, NewEntityListener>,
556-
pub(crate) windows: SlotMap<WindowId, Option<Window>>,
556+
pub(crate) windows: SlotMap<WindowId, Option<Box<Window>>>,
557557
pub(crate) window_handles: FxHashMap<WindowId, AnyWindowHandle>,
558558
pub(crate) focus_handles: Arc<FocusMap>,
559559
pub(crate) keymap: Rc<RefCell<Keymap>>,
@@ -964,7 +964,7 @@ impl App {
964964
clear.clear();
965965

966966
cx.window_handles.insert(id, window.handle);
967-
cx.windows.get_mut(id).unwrap().replace(window);
967+
cx.windows.get_mut(id).unwrap().replace(Box::new(window));
968968
Ok(handle)
969969
}
970970
Err(e) => {
@@ -1239,7 +1239,7 @@ impl App {
12391239
.windows
12401240
.values()
12411241
.filter_map(|window| {
1242-
let window = window.as_ref()?;
1242+
let window = window.as_deref()?;
12431243
window.invalidator.is_dirty().then_some(window.handle)
12441244
})
12451245
.collect::<Vec<_>>()
@@ -1320,7 +1320,7 @@ impl App {
13201320

13211321
fn apply_refresh_effect(&mut self) {
13221322
for window in self.windows.values_mut() {
1323-
if let Some(window) = window.as_mut() {
1323+
if let Some(window) = window.as_deref_mut() {
13241324
window.refreshing = true;
13251325
window.invalidator.set_dirty(true);
13261326
}
@@ -2199,7 +2199,7 @@ impl AppContext for App {
21992199
.windows
22002200
.get(window.id)
22012201
.context("window not found")?
2202-
.as_ref()
2202+
.as_deref()
22032203
.expect("attempted to read a window that is already on the stack");
22042204

22052205
let root_view = window.root.clone().unwrap();

crates/gpui/src/app/test_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl TestAppContext {
455455
.windows
456456
.get_mut(window.id)
457457
.unwrap()
458-
.as_mut()
458+
.as_deref_mut()
459459
.unwrap()
460460
.platform_window
461461
.as_test()

crates/gpui/src/window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4718,7 +4718,7 @@ impl<V: 'static + Render> WindowHandle<V> {
47184718
.get(self.id)
47194719
.and_then(|window| {
47204720
window
4721-
.as_ref()
4721+
.as_deref()
47224722
.and_then(|window| window.root.clone())
47234723
.map(|root_view| root_view.downcast::<V>())
47244724
})

0 commit comments

Comments
 (0)