Reduce panel allocations and fix transient surface leaks (#19)
Repeated panel updates rebuilt unchanged controls and SVG artwork, cloned composition data, and kept unused workspace icon resources. This reuses controls when their layout stays the same, bounds the SVG cache, removes temporary layout allocations, and releases icon resources when apps close or the workspace style changes. Rapidly closing a modal could also leave a native surface behind when its asynchronous creation finished after the close. Late openings now get destroyed when their owner is gone. Ferese uses the published `ferese-v0.1.2` Iced/libcosmic fixes so a temporary software buffer/viewport size mismatch retries the frame instead of crashing. Two runs per version of the same workspace/overview/reload workload measured **26% fewer allocated bytes and 23% fewer allocation calls**. A separate 1,800-cycle notification/modal stress run retained about **40 MiB less shell memory**, including shared-buffer retention falling from 28.2 MiB to 272 KiB. These are measured workload results, not an overall desktop speedup claim. Validation: - 1,350 workspace tests passed, including GPU Settings text rendering (50 optional tests ignored); formatting and Clippy passed. - Native continuous/island panel tests passed rapid notification resizing, modal cancellation, and live material/input-region changes. - A Wayland lifetime trace confirmed all 280 created modal surfaces were destroyed; longer DHAT traces and Intel GPU memory measurements were checked separately. - All installation binaries rebuilt and the installation bundle passed inventory and checksum verification.
This commit is contained in:
1 parent
65fcaef13f
commit
cf540f1feb
14 files changed
+403
-74
No files matched your search
@@ -18,7 +18,7 @@ libc.workspace = true
|
||||
# tiny-skia to avoid a second GPU initialization during desktop startup.
|
||||
libcosmic = { workspace = true, features = ["wgpu", "a11y"] }
|
||||
freedesktop-desktop-entry = { version = "0.8.3", default-features = false }
|
||||
iced_accessibility = { git = "https://github.com/ferese-wm/libcosmic", tag = "ferese-v0.1.1" }
|
||||
iced_accessibility = { git = "https://github.com/ferese-wm/libcosmic", tag = "ferese-v0.1.2" }
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
tempfile.workspace = true
|
||||
|
||||
@@ -131,16 +131,13 @@ impl FereseShell {
|
||||
.unwrap_or_default(),
|
||||
move |resolution| {
|
||||
let zone = |zone: &Zone| {
|
||||
let mut zone = zone.clone();
|
||||
for group in &mut zone.groups {
|
||||
group.items.retain(|item| matches!(resolution.items.get(&item.id), Some(Placement::Visible { width, .. }) if *width > 0.0));
|
||||
}
|
||||
view_zone(
|
||||
panel,
|
||||
&zone,
|
||||
zone,
|
||||
availability,
|
||||
shell_theme,
|
||||
compositor_material,
|
||||
|item| matches!(resolution.items.get(&item.id), Some(Placement::Visible { width, .. }) if *width > 0.0),
|
||||
|item, surface| {
|
||||
let Some(Placement::Visible { representation, width }) = resolution.items.get(&item.id)
|
||||
else {
|
||||
@@ -171,6 +168,7 @@ impl FereseShell {
|
||||
availability,
|
||||
shell_theme,
|
||||
compositor_material,
|
||||
|_| true,
|
||||
|item, surface| {
|
||||
self.view_panel_item(
|
||||
id,
|
||||
@@ -566,6 +564,7 @@ fn view_zone<'a>(
|
||||
availability: Availability,
|
||||
shell_theme: ShellTheme,
|
||||
compositor_material: bool,
|
||||
visible: impl Fn(&Item) -> bool,
|
||||
render: impl Fn(&Item, GroupSurface) -> (Element<'a, cosmic::Action<Message>>, bool),
|
||||
) -> Element<'a, cosmic::Action<Message>> {
|
||||
let bar = BarMetrics::from(panel.geometry);
|
||||
@@ -577,7 +576,11 @@ fn view_zone<'a>(
|
||||
let mut controls = row::with_capacity(group.items.len()).align_y(cosmic::iced::Alignment::Center);
|
||||
let mut count = 0;
|
||||
let mut has_content = false;
|
||||
for item in group.items.iter().filter(|item| item.available(availability)) {
|
||||
for item in group
|
||||
.items
|
||||
.iter()
|
||||
.filter(|item| item.available(availability) && visible(item))
|
||||
{
|
||||
if count > 0 {
|
||||
controls =
|
||||
controls.push(cosmic::iced::widget::Space::new().width(item.gap_before.unwrap_or(group.spacing)));
|
||||
@@ -1006,24 +1009,32 @@ mod island_tests {
|
||||
Some("tiny-skia"),
|
||||
))
|
||||
.unwrap();
|
||||
let view = view_zone(panel, zone, availability, theme, true, |item, _| {
|
||||
let width = match item.kind {
|
||||
ItemKind::Overview => 28.,
|
||||
ItemKind::Workspaces { .. } => 72.,
|
||||
ItemKind::FocusedWindow => 80.,
|
||||
ItemKind::Clock => 60.,
|
||||
_ => 20.,
|
||||
};
|
||||
let height = if matches!(item.kind, ItemKind::FocusedWindow) {
|
||||
24.
|
||||
} else {
|
||||
20.
|
||||
};
|
||||
(
|
||||
container(cosmic::iced::widget::Space::new().width(width).height(height)).into(),
|
||||
!matches!(item.kind, ItemKind::FocusedWindow) || title_content,
|
||||
)
|
||||
});
|
||||
let view = view_zone(
|
||||
panel,
|
||||
zone,
|
||||
availability,
|
||||
theme,
|
||||
true,
|
||||
|_| true,
|
||||
|item, _| {
|
||||
let width = match item.kind {
|
||||
ItemKind::Overview => 28.,
|
||||
ItemKind::Workspaces { .. } => 72.,
|
||||
ItemKind::FocusedWindow => 80.,
|
||||
ItemKind::Clock => 60.,
|
||||
_ => 20.,
|
||||
};
|
||||
let height = if matches!(item.kind, ItemKind::FocusedWindow) {
|
||||
24.
|
||||
} else {
|
||||
20.
|
||||
};
|
||||
(
|
||||
container(cosmic::iced::widget::Space::new().width(width).height(height)).into(),
|
||||
!matches!(item.kind, ItemKind::FocusedWindow) || title_content,
|
||||
)
|
||||
},
|
||||
);
|
||||
let mut view: Element<'_, cosmic::Action<Message>> = container(view)
|
||||
.height(panel.geometry.height)
|
||||
.align_y(alignment::Vertical::Center)
|
||||
|
||||
@@ -1378,6 +1378,36 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn late_open_checks_preserve_owned_desktop_widgets_and_tooltips() {
|
||||
let mut shell = shell_with_measured_panel();
|
||||
let wallpaper = window::Id::unique();
|
||||
let clock = window::Id::unique();
|
||||
let note = window::Id::unique();
|
||||
let tooltip = window::Id::unique();
|
||||
shell.outputs[0].wallpaper = Some(wallpaper);
|
||||
shell.outputs[0].clock = Some(clock);
|
||||
shell.outputs[0].notes.push(("note".into(), note));
|
||||
shell.workspace_ui.tooltip = Some(tooltip);
|
||||
for id in [wallpaper, clock, note, tooltip] {
|
||||
assert!(shell.owns_surface(id));
|
||||
assert_eq!(
|
||||
shell
|
||||
.handle_event(
|
||||
Event::Window(window::Event::Opened {
|
||||
position: None,
|
||||
size: cosmic::iced::Size::new(100., 100.),
|
||||
}),
|
||||
id,
|
||||
)
|
||||
.units(),
|
||||
0,
|
||||
"an owned surface must not be destroyed on opening"
|
||||
);
|
||||
}
|
||||
assert!(!shell.owns_surface(window::Id::unique()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_measured_panel_is_not_an_unmeasured_panel() {
|
||||
let mut shell = shell_with_measured_panel();
|
||||
|
||||
@@ -203,6 +203,22 @@ impl FereseShell {
|
||||
])
|
||||
}
|
||||
|
||||
pub(super) fn owns_surface(&self, id: window::Id) -> bool {
|
||||
self.outputs.iter().any(|entry| {
|
||||
entry.bar == id
|
||||
|| entry.wallpaper == Some(id)
|
||||
|| entry.clock == Some(id)
|
||||
|| entry.notes.iter().any(|(_, surface)| *surface == id)
|
||||
}) || self.menu.as_ref().is_some_and(|menu| menu.id == id)
|
||||
|| self.system_modal.as_ref().is_some_and(|modal| modal.contains(id))
|
||||
|| self
|
||||
.notification_surface
|
||||
.as_ref()
|
||||
.is_some_and(|surface| surface.id == id)
|
||||
|| self.workspace_ui.tooltip == Some(id)
|
||||
|| self.note_drag.as_ref().is_some_and(|drag| drag.overlay == id)
|
||||
}
|
||||
|
||||
pub(super) fn handle_event(&mut self, event: Event, id: window::Id) -> Task<Message> {
|
||||
if matches!(event, Event::Mouse(cosmic::iced::mouse::Event::CursorLeft)) {
|
||||
return self.dismiss_workspace_tooltip_for_bar(id);
|
||||
@@ -338,6 +354,15 @@ impl FereseShell {
|
||||
Event::PlatformSpecific(PlatformSpecific::Wayland(wayland::Event::Output(event, output))) => {
|
||||
self.output_event(event, output)
|
||||
}
|
||||
Event::Window(window::Event::Opened { .. }) if !self.owns_surface(id) => {
|
||||
// Creation is asynchronous. A close can arrive before the
|
||||
// surface exists, so dispose of any late opening once its
|
||||
// owner has gone away. IDs are never reused by the shell.
|
||||
Task::batch([
|
||||
destroy_layer_surface(id),
|
||||
cosmic::task::message(cosmic::Action::Surface(cosmic::surface::action::destroy_popup(id))),
|
||||
])
|
||||
}
|
||||
Event::Window(window::Event::Opened { .. })
|
||||
if self.outputs.iter().any(|entry| entry.bar == id)
|
||||
|| self.menu.as_ref().is_some_and(|menu| menu.id == id)
|
||||
|
||||
@@ -683,6 +683,33 @@ fn modal_focus_operation<T: Send + 'static>(backwards: bool) -> Box<dyn cosmic::
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_cancelled_modal_that_opens_late_is_destroyed_without_closing_its_replacement() {
|
||||
let mut app = crate::tests::shell_with_measured_panel();
|
||||
drop(app.open_guide(Vec::new()));
|
||||
let cancelled = app.system_modal.as_ref().unwrap().surfaces[0].id;
|
||||
assert!(app.owns_surface(cancelled));
|
||||
drop(app.destroy_system_modal(false));
|
||||
drop(app.open_guide(Vec::new()));
|
||||
let replacement = app.system_modal.as_ref().unwrap().surfaces[0].id;
|
||||
assert!(!app.owns_surface(cancelled));
|
||||
assert!(app.owns_surface(replacement));
|
||||
|
||||
let close = app.handle_event(
|
||||
Event::Window(window::Event::Opened {
|
||||
position: None,
|
||||
size: cosmic::iced::Size::new(800., 600.),
|
||||
}),
|
||||
cancelled,
|
||||
);
|
||||
assert_eq!(
|
||||
close.units(),
|
||||
2,
|
||||
"a late layer or popup must receive a destruction command"
|
||||
);
|
||||
assert!(app.owns_surface(replacement));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tab_stays_within_modal_actions_in_both_directions() {
|
||||
use cosmic::iced::Rectangle;
|
||||
|
||||
@@ -74,7 +74,7 @@ fn discover_icons(entries: Option<Arc<Vec<fde::DesktopEntry>>>, app_ids: Vec<Str
|
||||
let mut seen = HashSet::new();
|
||||
Arc::new(
|
||||
fde::Iter::new(fde::default_paths())
|
||||
.entries::<&str>(None)
|
||||
.entries::<&str>(Some(&[]))
|
||||
.filter(|entry| seen.insert(entry.appid.clone()))
|
||||
.filter(|entry| !entry.hidden())
|
||||
.collect(),
|
||||
@@ -402,7 +402,14 @@ impl WorkspaceUi {
|
||||
}
|
||||
|
||||
fn load_icons(&mut self, snapshot: &ShellSnapshot, needed: bool) -> Task<Message> {
|
||||
if !needed || self.icons_loading {
|
||||
if !needed {
|
||||
self.entries = None;
|
||||
self.icons = HashMap::new();
|
||||
return Task::none();
|
||||
}
|
||||
self.icons
|
||||
.retain(|id, _| snapshot.windows.iter().any(|window| &window.app_id == id));
|
||||
if self.icons_loading {
|
||||
return Task::none();
|
||||
}
|
||||
let app_ids: Vec<_> = snapshot
|
||||
@@ -517,6 +524,28 @@ mod tests {
|
||||
assert!(ui.icons.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn workspace_icon_storage_follows_running_apps_and_selected_style() {
|
||||
let mut ui = WorkspaceUi::default();
|
||||
let mut snapshot = snapshot(1);
|
||||
add_window(&mut snapshot, "running");
|
||||
ui.entries = Some(Arc::new(Vec::new()));
|
||||
for id in ["running", "closed"] {
|
||||
ui.icons
|
||||
.insert(id.into(), icon::from_svg_bytes(ferese_theme::icons::APPLICATION));
|
||||
}
|
||||
assert_eq!(ui.load_icons(&snapshot, true).units(), 0);
|
||||
assert!(ui.icons.contains_key("running"));
|
||||
assert!(!ui.icons.contains_key("closed"));
|
||||
assert!(ui.entries.is_some());
|
||||
ui.icons_loading = true;
|
||||
assert_eq!(ui.load_icons(&snapshot, false).units(), 0);
|
||||
assert!(ui.icons.is_empty());
|
||||
assert_eq!(ui.icons.capacity(), 0);
|
||||
assert!(ui.entries.is_none());
|
||||
assert!(ui.icons_loading, "an in-flight worker still owns its discovery request");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn icon_publication_preserves_existing_icons_and_queues_new_windows() {
|
||||
let mut shell = crate::tests::shell_with_measured_panel();
|
||||
|
||||
Reference in new issue
Block a user