Note that there are some explanatory texts on larger screens.

plurals
  1. POimage loading performance problems with python and gobject
    primarykey
    data
    text
    <p>I have a script with a GTK(GObject) interface I use for posting to my photo blog.</p> <p>I'm trying to improve it's responsiveness by loading the images in a background thread.</p> <p>I've had no luck trying to populate GdkPixbuf objects from a background thread, everything I've tried just jams solid.</p> <p>So as an alternate I thought I'd read the files in the background thread and then push them into GdkPixbuf's on demand. This approach has yielded some surprising and rather depressing performance results which make me wonder if I'm doing something grossly wrong.</p> <p>I'm playing with lightly compressed jpegs off my camera, they tend to be around 3.8mb.</p> <p>Here's the original blocking image load:</p> <pre><code>pb = GdkPixbuf.Pixbuf.new_from_file(image_file) </code></pre> <p>This averages about 550ms, not huge, but rather tedious if you want to flick through a dozen images.</p> <p>Then I split it up, here's the file read:</p> <pre><code>data = bytearray(open(self.image_file).read()) </code></pre> <p>This averages 15ms, that's really nice, but also kinda worrying, if we can read the file in 15ms what are the other 535ms being spent on?</p> <p>Incidentally the bytearray call exists because the PixBufLoader wouldn't accept the data otherwise.</p> <p>And then the Pixbuf load:</p> <pre><code>pbl = GdkPixbuf.PixbufLoader() pbl.write(data, len(data)) pbl.close() pb = pbl.get_pixbuf() </code></pre> <p>This averages around 1400ms, which is nearly 3 times longer than letting Gtk do it all.</p> <p>Am I doing something wrong here?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload