After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 760381 - Make cover art downloading async
Make cover art downloading async
Status: RESOLVED FIXED
Product: gnome-music
Classification: Applications
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gnome-music-maint
gnome-music-maint
Depends on:
Blocks:
 
 
Reported: 2016-01-09 22:56 UTC by Carlos Garnacho
Modified: 2016-01-10 23:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
albumArtCache: Use GIO async APIs to download cover art (9.44 KB, patch)
2016-01-09 22:57 UTC, Carlos Garnacho
committed Details | Review

Description Carlos Garnacho 2016-01-09 22:56:48 UTC
The current approach causes main thread stalls, leaving the UI barely responsive. This is most noticeable if you move aside all of ~/.cache/media-art and start gnome-music (NB, you may need the grilo-plugins patch in bug #760378, otherwise cover art won't be found).

I'm attaching a patch that does all the operation asynchronous using GIO APIs, it will still feel somewhat slow (esp. scrolling), but the UI will at least stay responsive.
Comment 1 Carlos Garnacho 2016-01-09 22:57:16 UTC
Created attachment 318610 [details] [review]
albumArtCache: Use GIO async APIs to download cover art

The previous approach of spawning a thread that made synchronous
calls resulted on long main thread stalls because of the GIL, using
GIO async APIs largely solves this problem.

Now we download cover art files in several stages:
1) Open the input stream from the http(s) url we get from grilo
2) Open the output stream for the corresponding ./cache/album-art
   file
3) Splice these together and wait for the transfer to be complete
4) Try getting a pixbuf again

All these stages are done asynchronously so the main thread
GMainContext is still able to process events while cover art
is being downloaded.

Additionally, The final phase of attempting to load the pixbuf
again is now performed by reusing the lookup() function, an
additional argument has been added so we can bail out if it
fails to load/find a pixbuf the second time again.

Also, remove the thread queue, and the corresponding signal, this
is now all unused.
Comment 2 Felipe Borges 2016-01-10 13:42:40 UTC
Review of attachment 318610 [details] [review]:

awesome Carlos!
Comment 3 Carlos Garnacho 2016-01-10 23:58:39 UTC
Cheers! Pushed to master.

Attachment 318610 [details] pushed as 9a045df - albumArtCache: Use GIO async APIs to download cover art