Bug 182743 - Renders system unresponsive on large image collections
Summary: Renders system unresponsive on large image collections
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Plugin-Generic-Presentation (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR major
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-01 16:50 UTC by Robert Zeller
Modified: 2018-03-23 11:28 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 0.6.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Zeller 2009-02-01 16:50:00 UTC
Version:           0.10.0-rc1 (using 4.1.3 (KDE 4.1.3) "release 70.1", KDE:KDE4:STABLE:Desktop / openSUSE_11.1)
Compiler:          gcc
OS:                Linux (i686) release 2.6.27.7-9-pae

I preferred "Advanced Slide Show" in previous versions of digikam because it has nice transition effects in between images. Unfortunately this does not work any more on albums with 50 or more images. digikam spawns numerous parallel  threads "kio_file", "kio_thumbnail", "dbus-launch", which obviously try to generate thumbnails of the images in parallel. After a little while, all my 2 GB of memory are exhausted and the system starts paging; which results in no responsiveness at all on any click, or keyboard entry. The only way to stop the numerous parallel processes is to power cycle the computer. To me it doesn't make any sense  to start more than four of these parallel threads on a one cpu system, because the cpu can only work on one thread at a time, the only sense of these parallel threads is to overlap io-operations with compute operations. I strongly suggest to limit the number of parallel threads to 4 when running "Advances Slide Show".
Thanks,
Robert
Comment 1 Andi Clemens 2009-02-06 09:41:12 UTC
I can not confirm this, works fine for test albums with over 2000 images...

Andi
Comment 2 caulier.gilles 2009-02-06 09:46:55 UTC
Same here. It's work fine with my huge collections

Gilles
Comment 3 Andi Clemens 2009-03-28 22:59:40 UTC
Hmm I must revoke my opinion, I now can confirm that opening a folder with 300 or more images will make "advanced slideshow" unresponsive for quite some time. I just tested it again.

Andi
Comment 4 Andi Clemens 2009-06-06 22:35:15 UTC
*** Bug 194355 has been marked as a duplicate of this bug. ***
Comment 5 Andi Clemens 2009-06-06 22:42:31 UTC
There are several problems with this plugin:

1. It will always load all images in the beginning. If you have an album open with 6000 images (for example a digiKam tag album), it will try to load all of them, even when a selection is made.
It is also much slower then in other plugins, I have not figured out why.
When I open 1900 images in RemoveRedEyes, it takes 5 seconds to load the image list.
But in AdvancedSlideshow, it takes over 4 minutes.

2. There seems to be no way to add only the selected images, and even when the dialog has been loaded, the "display only selected images" radiobutton is always grayed out.

3. When you finally managed to load the imageslist and start the slideshow, it takes, again, ages before the slideshow starts.

There might be performance issues from KIPI interface, but something is definitely also wrong in the plugin.

Gilles, as you know KIPI a little bit better, do you understand what is going wrong here?

The "slow part" can be found here:
http://lxr.kde.org/source/extragear/graphics/kipi-plugins/advancedslideshow/maindialog.cpp#537

There might be other parts that need to be checked.
Also KIPI should be checked. But right now I don't know what to do here.

Andi
Comment 6 Robert Zeller 2009-06-07 13:22:24 UTC
Andi,

thanks for confirming the bug. In my opinion the slowness of the system is caused by the fact that a huge number of parallel processes - probably for each slide three processes : "kio_file", "kio_thumbnail", "dbus-launch" - are being spawned. These parallel processes after a short while exhaust all the memory and the system starts paging like crazy. It should be relatively easy to limit the number of slides being processed in parallel to a reasonable number - say 4 - and continue processing in series on chunks of 4 slides. In this case it would still take some time to prepare the slide show, but the system would stay responsive, and after a little while the advanced slide show would start. 

Robert
Comment 7 Dominic Lyons 2009-06-07 15:38:56 UTC
Probably it would be the best to make some sort of queue to avoid running to many processes.

I think it also should be proved which of the operations are really necessary before the slide show dialog appears. I guess most of them could be done just in time when the slide show is running (for example always prepare the next 2-5 images and keep the same amount of already seen images in memory). And maybe some of the operations can be done with OpenGL (if it is not used till now).
Comment 8 Andi Clemens 2009-07-19 00:40:18 UTC
I fixed some memory leaks (but they were not responsible for the slow execution) and some other issues.
It should start a little bit faster, but still there are many strange things going on:

1. Why does this plugin consume over 800MB RAM, just by loading? I have not found an memory leak, so this must be a big misconception.

2. We seem to load the image infos all the time: when starting the plugin, when updating the list, when calling the startSlideShow slot etc. Although we have a sharedData object, we don't seem to use it properly. I guess data is duplicated or even tripled.

3. When the plugin is started and you click in the imageslist, you don't get the correct thumbnails.
Somehow the list is not completely loaded, so something must be active in the background.

4. We still use a lot of Qt3Support classes in this plugin.

5. We check for valid files when we start the slideshow, this takes time again. But why? I guess all files coming from the KIPI-Interface should be valid / existent, so why check this? It slows down the start of the slideshow.

Well that's enough for today, I will continue tomorrow analyzing this pluging.
Comment 9 caulier.gilles 2009-07-19 10:41:40 UTC
Andi,

Look like the is a cache mechanism in this plugin. I suspect that it's the problem:

http://lxr.kde.org/source/extragear/graphics/kipi-plugins/advancedslideshow/slideshowloader.h#45

http://lxr.kde.org/source/extragear/graphics/kipi-plugins/advancedslideshow/slideshowloader.cpp#112

Which is a map of KUrl and loaded QImage. It sound like there is no cache limit.

I think you just check how is filled this map. I suspect that current selection is pass is loadedThread, images are loaded as well, and after slide show is started. It's just my viewpoint, after to use slideshow with a huge images selection.

Gilles Caulier
Comment 10 Andi Clemens 2009-07-19 11:24:14 UTC
I have no cache enabled (you can set it in the dialog).
We are filling this KUrl map in three different places, and I don't understand why.

First, we get all images from KIPICollection Interface, and find out which are selected:
http://lxr.kde.org/source/extragear/graphics/kipi-plugins/advancedslideshow/maindialog.cpp#552

Then we update this list whenever something happens in the config dialog.
And in the end when the slideshow is loaded, we get this list again, without using the sharedData:
http://lxr.kde.org/source/extragear/graphics/kipi-plugins/advancedslideshow/plugin_advancedslideshow.cpp#192

The strange thing in the code above: We can never get the selected images, so a slideshow will always display a full album. But the slideshow config has a radiobutton to only display selected images (which is always grayed out anyway).
Also in the first code reference, we calculate the images by getting all images from the interface and keeping only those that belong to the current album path.
When the slideshow is started (second code reference), we just ignore all those urls and get the images with interface->currentAlbum.

This looks like a misconception to me, but maybe I don't understand the purpose here.

Anyway if the plugin is caching, it definitely doesn't have to do this on startup, only when pressing "Start Slideshow". And even then it should cache like 4-5 images, not more.
Comment 11 caulier.gilles 2009-07-19 12:20:37 UTC
I don't know exactly. Valerio has written this part. I have just polished code to compile fine under Win32.

I'm agree to to complete KDE4 port there. No need to lets Qt3 code until the end of the world. 

And this is true to all other plugins of course...

>Anyway if the plugin is caching, it definitely doesn't have to do this on
>startup, only when pressing "Start Slideshow". And even then it should cache
>like 4-5 images, not more.

I'm totally agree...

Gilles
Comment 12 Andi Clemens 2009-07-19 13:46:14 UTC
I guess I found a proof now that the image urls are not used properly:
I fixed the selection radiobutton, so if you select a range of images, you can use it in the advanced slideshow config dialog now.
But if you have selected images and start the slideshow, ALL images are shown again, not the selected ones.
This proofs to me what I have guessed before: we don't use the sharedData properly.

I will try to fix this now, and then check how to avoid the preloading of all the images, especially when the plugin is just loaded.
Comment 13 Andi Clemens 2009-07-20 13:15:53 UTC
One possible time and memory saver:
If "start SlideShow" is clicked, we read in information about exif comments and angle of each image, this can take some time.

Suggestion:
Do not read this info when the slideshow is started, but when an image is loaded. This way we don't have to wait so long for the slideshow to start up.
Comment 14 Andi Clemens 2009-07-20 20:05:51 UTC
SVN commit 1000030 by aclemens:

Quickfix: Do not create a list of comments/captions and angles when
starting the slideshow, this will be very slow if you have more then 300
images selected.
Instead read this info while images are loaded.

It is a quickfix because we still generate a fake comments and angle
list in slotSlideShow(), but with default values. I did it this way to
minimize code changes. In the future we might want to change the
slideshow classes instead.

Still the plugin wastes a lot of memory on startup, I have not found out
yet what produces this memory consumption.
Will need to do further checks.

CCBUG:182743

 M  +5 -2      plugin_advancedslideshow.cpp  
 M  +4 -2      slideshow.cpp  
 M  +13 -12    slideshowgl.cpp  
 M  +41 -16    slideshowloader.cpp  
 M  +7 -1      slideshowloader.h  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1000030
Comment 15 Andi Clemens 2009-07-21 14:17:07 UTC
SVN commit 1000476 by aclemens:

Add possibilities to set a size for ImagesList widget and
ImagesListView.
The default iconsize was SizeLarge, but this may be to large for
advancedslideshow.
We need something to setup an default iconsize.
ImagesListViewItem will get its iconsize from the associated view, and
ImagesListView and ImagesList widget take an optional size parameter
now.

This commit will also remove the creation of comments and tag
information, because the only plugin that needs it is advancedslideshow
and sendimages. If we add a lot of images to an ImagesList, it can take
a while to add this information.
If a plugin really needs this, it should call updateInformation() on the
ImagesListViewItem now, like sendimages does with this commit.

The next step will be to use ImagesList widget in advancedslideshow, to
factorize code.

CCBUG:182743

 M  +68 -31    common/libkipiplugins/imageslist.cpp  
 M  +26 -10    common/libkipiplugins/imageslist.h  
 M  +2 -0      sendimages/imagespage.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1000476
Comment 16 Andi Clemens 2009-07-21 18:38:49 UTC
I have added some commits that fix the memory consumption.
Now loading 5000 images on my computer doesn't allocate over 800MB RAM anymore, yeah! :)
Still the plugin needs more "love", there are things to polish, and thumbnail rendering (throughout digiKam) could be improved as well.

But at least this plugin is usable with many images now.

Robert,
if you have the time, please checkout latest KIPI SVN and tell me if it got better.

I will keep this report open, as there are more things to fix and I'm waiting for you response.

Andi
Comment 17 Robert Zeller 2009-07-21 21:08:49 UTC
Andi,

thanks for the information ; sounds good to me
.
Please leave me some time to check out things, I am using a standard
open suse 11.1 distribution here. I would have to install the kipi-svn
version first and also svn version of digikam; but am busy with other
things right now.
I appreciate very much your endeavor.

Robert


Andi Clemens wrote:
> https://bugs.kde.org/show_bug.cgi?id=182743
>
>
>
>
>
> --- Comment #16 from Andi Clemens <andi clemens gmx net>  2009-07-21 18:38:49 ---
> I have added some commits that fix the memory consumption.
> Now loading 5000 images on my computer doesn't allocate over 800MB RAM anymore,
> yeah! :)
> Still the plugin needs more "love", there are things to polish, and thumbnail
> rendering (throughout digiKam) could be improved as well.
>
> But at least this plugin is usable with many images now.
>
> Robert,
> if you have the time, please checkout latest KIPI SVN and tell me if it got
> better.
>
> I will keep this report open, as there are more things to fix and I'm waiting
> for you response.
>
> Andi
>
>
Comment 18 Andi Clemens 2009-07-21 21:25:34 UTC
No problem :)
We will release kipi-plugins 0.5.0 this weekend, so the fixed will be in this release.
Also I don't think you need digiKam-svn to use the new kipi-plugins package.

Andi
Comment 19 Andi Clemens 2009-07-30 12:46:41 UTC
Robert,

I will close this one. I'm pretty sure it is fixed and some similar bugreport was closed as well, since the user could confirm that memory and performance issues have been fixed.

If you test this bug when you have some more time left still discover the problems described in here, feel free to re-open the report.

Andi
Comment 20 Robert Zeller 2009-07-30 13:26:33 UTC
Andi,
I just compiled kipi-plugins-0.5.0 and digikam-1.0.0-beta3 and started
advanced slide show on a collection with some 700 images. Looks like it
is working perfectly now. No delays and I see only one thread. I agree :
problem seems to be fixed now. Thanks again, Robert.

Andi Clemens wrote:
> https://bugs.kde.org/show_bug.cgi?id=182743
>
>
> Andi Clemens <andi.clemens@gmx.net> changed:
>
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|ASSIGNED                    |RESOLVED
>          Resolution|                            |FIXED
>
>
>
>
> --- Comment #19 from Andi Clemens <andi clemens gmx net>  2009-07-30 12:46:41 ---
> Robert,
>
> I will close this one. I'm pretty sure it is fixed and some similar bugreport
> was closed as well, since the user could confirm that memory and performance
> issues have been fixed.
>
> If you test this bug when you have some more time left still discover the
> problems described in here, feel free to re-open the report.
>
> Andi
>
>