Preloading Images

So I’m looking to make an application where images are loaded (only one is visible at a time), and the user looks through them.

I would prefer the images be preloaded in advance, so the application does not have to spend time waiting around for them to load. I’ve already done a bit of experimenting with how that will work (Using various Arc / Mutex / ArcSwap methods) in a subscription.

The part I’m looking to improve is how I store the image. In my mind, the best way to do that would be to just create the actual widget, then plop a reference to it in the fn view function. However Since Image doesn’t implement clone and From<&iced::widget::Image> is not implemented for Element<>, it makes it impossible.

Right now, I’m storing the bytes to the image (using iced::widget::image::Handle::from_bytes), and it still seems to take a little bit for images to load (maybe about ~1 second or so). It only takes about 3ms to load the image into memory, and “<200µs” to run fn view. (Though the image doesn’t actually appear for a little bit)

Is there a better way to do this? Or is this about as good as it will get, and I should just look at optimizing the preloading subscription part.

(Yes I’m running on --release). Images vary from 1920x1080 - 4000x6000.

Store the handles in your state. You can clone them without any performance penalty.