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.
This commit is contained in:
parent
bb15f30fe5
commit
93dd775f3c
2 changed files with 13 additions and 3 deletions
|
|
@ -199,6 +199,7 @@ fn network_scan(uri: &str, sizes: IconSizes) -> Result<Vec<tab::Item>, String> {
|
||||||
metadata,
|
metadata,
|
||||||
hidden,
|
hidden,
|
||||||
location_opt: Some(location),
|
location_opt: Some(location),
|
||||||
|
image_dimensions: None,
|
||||||
mime,
|
mime,
|
||||||
icon_handle_grid,
|
icon_handle_grid,
|
||||||
icon_handle_list,
|
icon_handle_list,
|
||||||
|
|
|
||||||
15
src/tab.rs
15
src/tab.rs
|
|
@ -708,6 +708,9 @@ pub fn item_from_gvfs_info(path: PathBuf, file_info: gio::FileInfo, sizes: IconS
|
||||||
children_opt,
|
children_opt,
|
||||||
},
|
},
|
||||||
hidden,
|
hidden,
|
||||||
|
image_dimensions: (!remote && mime.type_() == mime::IMAGE)
|
||||||
|
.then(|| image::image_dimensions(&path).ok())
|
||||||
|
.flatten(),
|
||||||
location_opt: Some(Location::Path(path)),
|
location_opt: Some(Location::Path(path)),
|
||||||
mime,
|
mime,
|
||||||
icon_handle_grid,
|
icon_handle_grid,
|
||||||
|
|
@ -843,6 +846,7 @@ pub fn item_from_entry(
|
||||||
},
|
},
|
||||||
hidden,
|
hidden,
|
||||||
location_opt: Some(Location::Path(path)),
|
location_opt: Some(Location::Path(path)),
|
||||||
|
image_dimensions: None,
|
||||||
mime,
|
mime,
|
||||||
icon_handle_grid,
|
icon_handle_grid,
|
||||||
icon_handle_list,
|
icon_handle_list,
|
||||||
|
|
@ -896,6 +900,9 @@ pub fn item_from_trash_entry(
|
||||||
metadata: ItemMetadata::Trash { metadata, entry },
|
metadata: ItemMetadata::Trash { metadata, entry },
|
||||||
hidden: false,
|
hidden: false,
|
||||||
location_opt: None,
|
location_opt: None,
|
||||||
|
image_dimensions: (mime.type_() == mime::IMAGE)
|
||||||
|
.then(|| image::image_dimensions(&original_path).ok())
|
||||||
|
.flatten(),
|
||||||
mime,
|
mime,
|
||||||
icon_handle_grid,
|
icon_handle_grid,
|
||||||
icon_handle_list,
|
icon_handle_list,
|
||||||
|
|
@ -1444,6 +1451,7 @@ pub fn scan_desktop(
|
||||||
metadata,
|
metadata,
|
||||||
hidden: false,
|
hidden: false,
|
||||||
location_opt: Some(Location::Trash),
|
location_opt: Some(Location::Trash),
|
||||||
|
image_dimensions: None,
|
||||||
mime,
|
mime,
|
||||||
icon_handle_grid,
|
icon_handle_grid,
|
||||||
icon_handle_list,
|
icon_handle_list,
|
||||||
|
|
@ -2319,6 +2327,7 @@ pub struct Item {
|
||||||
pub hidden: bool,
|
pub hidden: bool,
|
||||||
pub location_opt: Option<Location>,
|
pub location_opt: Option<Location>,
|
||||||
pub mime: Mime,
|
pub mime: Mime,
|
||||||
|
pub image_dimensions: Option<(u32, u32)>,
|
||||||
pub icon_handle_grid: widget::icon::Handle,
|
pub icon_handle_grid: widget::icon::Handle,
|
||||||
pub icon_handle_list: widget::icon::Handle,
|
pub icon_handle_list: widget::icon::Handle,
|
||||||
pub icon_handle_list_condensed: 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
|
// Determine effective memory budget based on image size
|
||||||
let (effective_max_mb, effective_jobs) = if mime.type_() == mime::IMAGE {
|
let (effective_max_mb, effective_jobs) = if mime.type_() == mime::IMAGE {
|
||||||
match image::image_dimensions(&path) {
|
match item.image_dimensions {
|
||||||
Ok((width, height)) => {
|
Some((width, height)) => {
|
||||||
let (_use_dedicated, eff_mb, eff_jobs) =
|
let (_use_dedicated, eff_mb, eff_jobs) =
|
||||||
should_use_dedicated_worker(width, height, max_mb, max_jobs);
|
should_use_dedicated_worker(width, height, max_mb, max_jobs);
|
||||||
(eff_mb, eff_jobs)
|
(eff_mb, eff_jobs)
|
||||||
}
|
}
|
||||||
Err(_) => (max_mb, max_jobs),
|
None => (max_mb, max_jobs),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(max_mb, max_jobs)
|
(max_mb, max_jobs)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue