Bug 435377

Summary: Speed up image preview
Product: [Applications] digikam Reporter: Philipp Keck <philipp.keck>
Component: Preview-ImageAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: wishlist CC: caulier.gilles, metzpinguin
Priority: NOR    
Version First Reported In: 7.2.0   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed/Implemented In: 8.0.0
Sentry Crash Report:
Attachments: DigiKam extra log statements when displaying an already-cached image preview

Description Philipp Keck 2021-04-05 08:46:17 UTC
SUMMARY

I'm migrating from Picasa to digiKam. My photos are on an SSD. I copied one of my (smaller) folder with photos so that it's "new" for both Picasa and digiKam. Then, in each program, I double-click the first photo to open the larger view and use the left/right arrow keys to navigate. Picasa reacts instantly, but digiKam has a 300-500ms delay until the full image is displayed. It doesn't hang, so I can navigate past 10 images as fast as I can press the key plus 500ms, but still it's annoying and makes it difficult to quickly compare adjacent similar images.

STEPS TO REPRODUCE
1. Go to "Preview" mode on any album that has a couple photos in it.
2. Press the "right" key to navigate to the next photo.

OBSERVED RESULT

The UI takes several hundred milliseconds to update, for both the selection in the image list at the top as well as the preview image below.

EXPECTED RESULT

Updates near-instantaneously (I believe I couldn't notice <50ms delays).


SOFTWARE/OS VERSIONS
Windows: 10
Linux/KDE Plasma: I'll test on this very soon and I strongly suspect it's the same issue there.
KDE Frameworks Version: 5.78.0
Qt Version: 5.15.2

ADDITIONAL INFORMATION

tl;dr: Possible implementations are a look-ahead cache and, when that's not enough, upsizing the thumbnail until the full image is loaded.

I have an SSD. Anyway I believe Picasa achieves this by pre-loading the next 2-5 photos into RAM and pre-rendering them to the resolution of the preview image, so that when I press the button, only a few bytes need to be swapped out in memory. When I click 4 photos ahead in Picasa, it also takes 500ms to load, so presumably that wasn't cached yet, which is fine. But still it immediately displays an upsized thumbnail, which looks quite fast/smooth with only a minor glitch when the full-resolution image is displayed shortly after.
Comment 1 Maik Qualmann 2021-04-05 08:57:37 UTC
I cannot reproduce the problem here, I can easily switch between 2 images without delay. My computer only has a dual core CPU. digiKam has a cache for preview images and also loads images in advance. The cache has a maximum of 200 MB, which may not be enough for extremely large images.

Maik
Comment 2 Maik Qualmann 2021-04-05 10:37:10 UTC
Git commit 5eb72429c888eb1dfce676269064e709a1008ec7 by Maik Qualmann.
Committed on 05/04/2021 at 10:36.
Pushed by mqualmann into branch 'master'.

allow up to 400MB preview cache

M  +2    -2    core/libs/threadimageio/fileio/loadingcache.cpp

https://invent.kde.org/graphics/digikam/commit/5eb72429c888eb1dfce676269064e709a1008ec7
Comment 3 caulier.gilles 2021-04-05 14:02:39 UTC
There is already a preview image cache mechanism in digiKam core.

Gilles Caulier
Comment 4 caulier.gilles 2021-04-24 12:13:46 UTC
Phillipp,

Can you double check if the problem remain with the digiKam 7.3.0 daily pre-release bundles published here:

https://files.kde.org/digikam/

Gilles Caulier
Comment 5 Philipp Keck 2021-05-04 18:34:04 UTC
FTR, this reproduces with 6.4.0 under Mint. I'll try 7.3.0 next.
Comment 6 Philipp Keck 2021-05-04 19:25:25 UTC
7.3.0 isn't faster under Windows either.

Now that I had the direct comparison, I noticed that it is faster under Mint. I recorded it with a screencasting tool on both OSes. On Mint, around 150ms pass between pressing the key (specifically, the keypress being visualized by a tool like Screenkeys) and the new image being rendered. On Windows it's around 300ms (which aligns with my original ~500ms estimate). Both OSes use the same SSD.

150ms isn't super bad, but I can still hit the arrow key much more frequently than that (roughly every 80ms), and also with Picasa I could "see" the images flying by at that speed, so ideally the images would render in <50ms or even <10ms, which would allow me to stop at the right image while moving fast, i.e. not overshooting. Also it just makes for a much smoother user experience overall, if the delay isn't noticeable.
Comment 7 caulier.gilles 2021-05-05 08:59:59 UTC
Phillip,

Check well the Setup/Views/Preview dialog page and look the preview settings:

"Previews shows embedded preview if available (faster)"

In the same page, for Raw file enable also the option to use 8 bits color depth. It's faster. 

Gilles Caulier
Comment 8 Philipp Keck 2021-05-05 18:07:59 UTC
Thanks. Those preview settings were already set the way you suggest. FWIW, flipping them the other way doesn't help either. And FTR my images are JPG, so the RAW settings shouldn't matter.
Comment 9 Philipp Keck 2021-07-18 19:09:42 UTC
Created attachment 140166 [details]
DigiKam extra log statements when displaying an already-cached image preview

I've inserted some log statements. When measuring the delay very approximately (with my eyes), I think it's around 300ms. The log messages (see attachment) account for 200ms, which I think is a good start.

70ms are lost between calling ItemViewCategorized::setCurrentIndex() (which is in between the ItemViewCategorized::toIndex() log statements) and when DImgPreviewItem::setPath() is hit with the new path. I haven't figured out how exactly this call works -- maybe there's just a whole lot of (non-essential) statements on the way that consume this time, or maybe it uses some kind of event mechanism that takes a while for the UI thread to get around to doing the work.

Another 100ms are lost on painting, specifically the scaling in GraphicsDImgItem::paint(): https://invent.kde.org/graphics/digikam/-/blob/master/core/libs/widgets/graphicsview/graphicsdimgitem.cpp#L260-270
While there's a cache (elsewhere) for file previews read from disk and there's a cache for resized images (cachedPixmaps), the latter is cleared when switching to another image (because it's not keyed by the filepath and presumably only serves to make zooming/panning faster). So when switching back and forth between images that are already (pre)loaded, there's no cache and the scaling has to happen every time.

I think extending that cache to retain previously painted pixmaps of other images/files isn't enough, as when moving forward through an album, all images are rendered only once. So much like the image preloading, the scaling would have to happen before the image is rendered for the first time. That might be hard to do in practice, as it requires knowing the rendering details like size/coordinates from GraphicsDImgItem::paint().

So while I'm convinced and can measure that this delay is real, and Picasa was certainly much faster in this regard (no noticeable delay), there doesn't seem to be any low-hanging fruit wrt. optimizing this.
Comment 10 Maik Qualmann 2021-07-18 21:02:01 UTC
I'll definitely have a look at it in the future, but I don't find digiKam to be slow, at least not here under Linux - on the contrary - I don't want to name any names - but I find other image viewers slower. My computer is still just a double core. I only know Picasa in the VM and don't find it any faster than digiKam.

If I switch between 2 images under Linux that are already in the cache, I don't see any delay, 300ms would be extreme ... 

Maik
Comment 11 Maik Qualmann 2022-01-31 18:09:41 UTC
Git commit 41efc2706c3770687e8773c1b713c19b3c57cecb by Maik Qualmann.
Committed on 31/01/2022 at 18:07.
Pushed by mqualmann into branch 'master'.

load faces and focus point only if enabled
It takes time if change images quickly when the focus point
is loaded every time, even if the focus display is deactivated.

M  +57   -7    core/app/views/preview/itempreviewview.cpp

https://invent.kde.org/graphics/digikam/commit/41efc2706c3770687e8773c1b713c19b3c57cecb
Comment 12 Maik Qualmann 2022-06-05 20:13:58 UTC
Git commit 20602a074e1c14095e20c1323329be2049c6c13d by Maik Qualmann.
Committed on 05/06/2022 at 20:12.
Pushed by mqualmann into branch 'master'.

store color converted preview image to cache
Depending on the color profile, the conversion can take a long time.
FIXED-IN: 8.0.0

M  +2    -1    NEWS
M  +14   -4    core/libs/threadimageio/preview/previewtask.cpp

https://invent.kde.org/graphics/digikam/commit/20602a074e1c14095e20c1323329be2049c6c13d