From e81a28e57e6169c69f00bf787a699ef3bb30f68a Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 12 May 2021 19:28:48 -0600 Subject: [PATCH 1/3] Remove dropped entities after every effect --- gpui/src/app.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpui/src/app.rs b/gpui/src/app.rs index d539314bb7..469b9b8ac1 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -1064,8 +1064,8 @@ impl MutableAppContext { self.focus(window_id, view_id); } } - } else { self.remove_dropped_entities(); + } else { self.update_windows(); if self.pending_effects.is_empty() { From 9dac491ed5f9b40e5f30056c6e7ea3fbddf31549 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 12 May 2021 19:29:17 -0600 Subject: [PATCH 2/3] Don't remove entities whose ref count has become positive again --- gpui/src/app.rs | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/gpui/src/app.rs b/gpui/src/app.rs index 469b9b8ac1..dab7508689 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -18,7 +18,7 @@ use smol::prelude::*; use std::{ any::{type_name, Any, TypeId}, cell::RefCell, - collections::{HashMap, HashSet, VecDeque}, + collections::{hash_map::Entry, HashMap, HashSet, VecDeque}, fmt::{self, Debug}, hash::{Hash, Hasher}, marker::PhantomData, @@ -1988,7 +1988,7 @@ pub struct ModelHandle { impl ModelHandle { fn new(model_id: usize, ref_counts: &Arc>) -> Self { - ref_counts.lock().inc_entity(model_id); + ref_counts.lock().inc_model(model_id); Self { model_id, model_type: PhantomData, @@ -2089,7 +2089,7 @@ impl ModelHandle { impl Clone for ModelHandle { fn clone(&self) -> Self { - self.ref_counts.lock().inc_entity(self.model_id); + self.ref_counts.lock().inc_model(self.model_id); Self { model_id: self.model_id, model_type: PhantomData, @@ -2186,7 +2186,7 @@ pub struct ViewHandle { impl ViewHandle { fn new(window_id: usize, view_id: usize, ref_counts: &Arc>) -> Self { - ref_counts.lock().inc_entity(view_id); + ref_counts.lock().inc_view(window_id, view_id); Self { window_id, view_id, @@ -2298,7 +2298,9 @@ impl ViewHandle { impl Clone for ViewHandle { fn clone(&self) -> Self { - self.ref_counts.lock().inc_entity(self.view_id); + self.ref_counts + .lock() + .inc_view(self.window_id, self.view_id); Self { window_id: self.window_id, view_id: self.view_id, @@ -2380,7 +2382,9 @@ impl AnyViewHandle { impl Clone for AnyViewHandle { fn clone(&self) -> Self { - self.ref_counts.lock().inc_entity(self.view_id); + self.ref_counts + .lock() + .inc_view(self.window_id, self.view_id); Self { window_id: self.window_id, view_id: self.view_id, @@ -2392,7 +2396,10 @@ impl Clone for AnyViewHandle { impl From<&ViewHandle> for AnyViewHandle { fn from(handle: &ViewHandle) -> Self { - handle.ref_counts.lock().inc_entity(handle.view_id); + handle + .ref_counts + .lock() + .inc_view(handle.window_id, handle.view_id); AnyViewHandle { window_id: handle.window_id, view_id: handle.view_id, @@ -2433,7 +2440,7 @@ pub struct AnyModelHandle { impl From> for AnyModelHandle { fn from(handle: ModelHandle) -> Self { - handle.ref_counts.lock().inc_entity(handle.model_id); + handle.ref_counts.lock().inc_model(handle.model_id); Self { model_id: handle.model_id, ref_counts: handle.ref_counts.clone(), @@ -2542,8 +2549,24 @@ struct RefCounts { } impl RefCounts { - fn inc_entity(&mut self, entity_id: usize) { - *self.entity_counts.entry(entity_id).or_insert(0) += 1; + fn inc_model(&mut self, model_id: usize) { + match self.entity_counts.entry(model_id) { + Entry::Occupied(mut entry) => *entry.get_mut() += 1, + Entry::Vacant(entry) => { + entry.insert(1); + self.dropped_models.remove(&model_id); + } + } + } + + fn inc_view(&mut self, window_id: usize, view_id: usize) { + match self.entity_counts.entry(view_id) { + Entry::Occupied(mut entry) => *entry.get_mut() += 1, + Entry::Vacant(entry) => { + entry.insert(1); + self.dropped_views.remove(&(window_id, view_id)); + } + } } fn inc_value(&mut self, tag_type_id: TypeId, id: usize) { From 493643c15fcf65f81912faf8e427acdcfd7ca004 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 12 May 2021 19:45:45 -0700 Subject: [PATCH 3/3] Remove dropped entities even if there are no effects to flush --- gpui/src/app.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/gpui/src/app.rs b/gpui/src/app.rs index dab7508689..c4df05ffb8 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -1066,6 +1066,7 @@ impl MutableAppContext { } self.remove_dropped_entities(); } else { + self.remove_dropped_entities(); self.update_windows(); if self.pending_effects.is_empty() {