Speeding up thumbnail generation (like multi threaded). Thoughts please.


Before you read on. I wasn't sure if this needs to go to the gtk-devel
or the nautilus mailing lists. I did gtk for now. I hope that's the
right list for things like this.

It has been a few years ago since i made a topic about this (on the
nautilus list)  with the title (rough guess) "nautilus thumbnail
generation slow".
Back then i didn't know shit about that stuff and i was thinking
nautilus used GD to generate thumbnails. Oh men was i wrong there.

Now, a few years later, i have some c and c++ knowledge and i
benchmarked the thumbnail generation of glib against GraphicsMagick
and FreeImage. no QT yet.
The results are from a folder with 1927 images all wallpaper sized and
double wallpaper sized. Image sizes ranges from 200KB up till a few
mega bytes per image. I scaled them all down to a max width or height
of 200 px by using this:

static GdkPixbuf *
scale_pixbuf_preserve_aspect_ratio (GdkPixbuf *pixbuf,
                                    gint size,
                                    GdkInterpType interp)
    GdkPixbuf *new_icon;
    gdouble w, h, new_width, new_height, max_edge;

    w = gdk_pixbuf_get_width (pixbuf);
    h = gdk_pixbuf_get_height (pixbuf);
    max_edge = MAX (w, h);
    new_width = size * (w / max_edge);
    new_height = size * (h / max_edge);

    /* Scale the image down, preserving the aspect ratio */
    new_icon = gdk_pixbuf_scale_simple (pixbuf, (gint)new_width,
(gint)new_height, interp);

    return new_icon;

That comes from the ubuntu wiki, just so you know before you attack me
on the code ^_^
All thumbnails where generated (in every single benchmark with every
image) on the bilinear flag for best quality.

Now for the results:

1927 images thumbnailed in 2.29 minutes. That is roughly 0.07 seconds
per thumbnail

1927 images thumbnailed in 3.08 minutes. That is roughly 0.09 seconds
per thumbnail

1927 images thumbnailed in 5.45 minutes. That is roughly 0.17 seconds
per thumbnail

Now first a sorry for the message i send to this list a few years ago
about nautilus being slow. Nautilus isn't slow as it uses glib and
glib is the clear winner here. Nautilus might have some strange things
in the code tht displays the thumbnails (didn't look) but the
generating if it is far from slow.

Now to speed it up even more.
I don't quite know how the bilinear algorithm works in glib. i've
looked at it but is kinda messy to just dive in but if it is something
that can be done in a multi threaded way then that would be the ideal
place to do it while all other programs using the code (like nautilus)
just get the performance boost without changing a single line. This
might be a little to hard to do or perhaps not even possible with the
current algorithm (thoughts on that please) so another way to speed it
up might be in the applications that use the code (again like
nautilus) you can make threads there where there is a list of known
files to thumbnail it can't be that hard to split that list in 4
(depending on your cores) and just let each core render a list of
thumbnails. I don't know the ins and outs of how this would be the
most logical way but i do know that on my pc just 1 of the 4 cores is
used which is a waste of those other 3 cores.

I personally haven't done any multi threading yet so don't count on
quality code if i do this ^_^

So, is there anyone here that has experienced with this? is there
anyone i an work with on this? actually anyone that could help me
through this? i'm brand new in glib and new to programming in general.
I would like to give this a try but i'm afraid i can't do this alone.
So any information about this, help and thoughts would be nice.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]