perf: use tokio

not sure how much this helps practically
This commit is contained in:
electria 2026-08-14 09:16:54 -07:00
commit da1e64d898
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
3 changed files with 21 additions and 5 deletions

11
Cargo.lock generated
View file

@ -1429,6 +1429,7 @@ dependencies = [
"rayon", "rayon",
"rfd", "rfd",
"size", "size",
"tokio",
"zip", "zip",
] ]
@ -1745,6 +1746,7 @@ dependencies = [
"iced_core", "iced_core",
"log", "log",
"rustc-hash 2.1.3", "rustc-hash 2.1.3",
"tokio",
"wasm-bindgen-futures", "wasm-bindgen-futures",
"wasmtimer", "wasmtimer",
] ]
@ -4259,6 +4261,15 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed"
dependencies = [
"pin-project-lite",
]
[[package]] [[package]]
name = "toml" name = "toml"
version = "1.1.4+spec-1.1.0" version = "1.1.4+spec-1.1.0"

View file

@ -10,11 +10,12 @@ kra-image-integration = "0.1.0"
rayon = "1.12.0" rayon = "1.12.0"
rfd = "0.17.2" rfd = "0.17.2"
size = "0.5.0" size = "0.5.0"
tokio = "1.53.1"
zip = "8.6.0" zip = "8.6.0"
[dependencies.iced] [dependencies.iced]
version = "0.14.0" version = "0.14.0"
features = [ "image" ] features = [ "image", "tokio" ]
[dependencies.image] [dependencies.image]
version = "0.25.10" version = "0.25.10"

View file

@ -75,9 +75,13 @@ impl State {
let size = 1000 / self.columns as u32; let size = 1000 / self.columns as u32;
let (task, handle) = Task::perform( let (task, handle) = Task::perform(
async move { async move {
tokio::task::spawn_blocking(move || {
utils::load_thumbnail(&path, size) utils::load_thumbnail(&path, size)
.map(|img| (path, handle_from_image(img))) .map(|img| (path, handle_from_image(img)))
.map_err(Arc::new) .map_err(Arc::new)
})
.await
.unwrap()
}, },
Message::ImageLoaded, Message::ImageLoaded,
) )
@ -194,7 +198,7 @@ impl State {
|handle| widget::image(handle).into(), |handle| widget::image(handle).into(),
)) ))
.key(self.key) .key(self.key)
.anticipate(2000) .anticipate(500)
.on_show(|_size| Message::LoadImage(path.clone())) .on_show(|_size| Message::LoadImage(path.clone()))
.on_hide(Message::UnloadImage(path.clone())), .on_hide(Message::UnloadImage(path.clone())),
) )