From 93dd775f3c6452ec8b82998d002b7351085c70a5 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Tue, 14 Apr 2026 16:23:10 +0200 Subject: [PATCH] perf: get image dimensions from background thread This caused the tab subscription to block the tokio executor. Instead store the image dimensions in the `Item`, which is created on a background thread. --- src/mounter/gvfs.rs | 1 + src/tab.rs | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/mounter/gvfs.rs b/src/mounter/gvfs.rs index cd4ea68..8ac42dc 100644 --- a/src/mounter/gvfs.rs +++ b/src/mounter/gvfs.rs @@ -199,6 +199,7 @@ fn network_scan(uri: &str, sizes: IconSizes) -> Result, String> { metadata, hidden, location_opt: Some(location), + image_dimensions: None, mime, icon_handle_grid, icon_handle_list, diff --git a/src/tab.rs b/src/tab.rs index b0b3a34..1e63588 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -708,6 +708,9 @@ pub fn item_from_gvfs_info(path: PathBuf, file_info: gio::FileInfo, sizes: IconS children_opt, }, hidden, + image_dimensions: (!remote && mime.type_() == mime::IMAGE) + .then(|| image::image_dimensions(&path).ok()) + .flatten(), location_opt: Some(Location::Path(path)), mime, icon_handle_grid, @@ -843,6 +846,7 @@ pub fn item_from_entry( }, hidden, location_opt: Some(Location::Path(path)), + image_dimensions: None, mime, icon_handle_grid, icon_handle_list, @@ -896,6 +900,9 @@ pub fn item_from_trash_entry( metadata: ItemMetadata::Trash { metadata, entry }, hidden: false, location_opt: None, + image_dimensions: (mime.type_() == mime::IMAGE) + .then(|| image::image_dimensions(&original_path).ok()) + .flatten(), mime, icon_handle_grid, icon_handle_list, @@ -1444,6 +1451,7 @@ pub fn scan_desktop( metadata, hidden: false, location_opt: Some(Location::Trash), + image_dimensions: None, mime, icon_handle_grid, icon_handle_list, @@ -2319,6 +2327,7 @@ pub struct Item { pub hidden: bool, pub location_opt: Option, pub mime: Mime, + pub image_dimensions: Option<(u32, u32)>, pub icon_handle_grid: widget::icon::Handle, pub icon_handle_list: widget::icon::Handle, pub icon_handle_list_condensed: widget::icon::Handle, @@ -6713,13 +6722,13 @@ impl Tab { // Determine effective memory budget based on image size let (effective_max_mb, effective_jobs) = if mime.type_() == mime::IMAGE { - match image::image_dimensions(&path) { - Ok((width, height)) => { + match item.image_dimensions { + Some((width, height)) => { let (_use_dedicated, eff_mb, eff_jobs) = should_use_dedicated_worker(width, height, max_mb, max_jobs); (eff_mb, eff_jobs) } - Err(_) => (max_mb, max_jobs), + None => (max_mb, max_jobs), } } else { (max_mb, max_jobs)