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 747794 - background reloaded more than necessary
background reloaded more than necessary
Status: RESOLVED FIXED
Product: gnome-shell
Classification: Core
Component: background
3.25.x
Other Linux
: Normal normal
: ---
Assigned To: gnome-shell-maint
gnome-shell-maint
Depends on:
Blocks:
 
 
Reported: 2015-04-13 18:23 UTC by Fabrice Bellet
Modified: 2017-08-01 09:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
background: use of CHANGES_DONE_HINT events to avoid reloads (1.54 KB, patch)
2017-07-31 15:19 UTC, Cosimo Cecchi
committed Details | Review

Description Fabrice Bellet 2015-04-13 18:23:18 UTC
I noticed that just creating a new background file on the filesystem causes many file-changed events in gnome-shell, that in cascade cause a texture for identical content to be created, without being used, because the image is purged from the cache in mutter just after its creation. Here is a log generated with some debug statement added  in gnome-shell and in mutter. This log is generated by overwriting the background.jpg file just _one_ time :

Gjs-Message: JS LOG: _load=/home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_load: 2ae5300: /home/bellet/Documents/Meteosat/background.jpg
Gjs-Message: JS LOG: monitorFile=/home/bellet/Documents/Meteosat/background.jpg
Gjs-Message: JS LOG: _load=/usr/share/backgrounds/gnome/adwaita-lock.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_load: 2ae5580: /usr/share/backgrounds/gnome/adwaita-lock.jpg
Gjs-Message: JS LOG: monitorFile=/usr/share/backgrounds/gnome/adwaita-lock.jpg
(gnome-shell:4810): mutter-DEBUG: load_file: 2ae5300: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: load_file: 2ae5580: /usr/share/backgrounds/gnome/adwaita-lock.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_load: 2bdccc0: /usr/share/gnome-shell/theme/noise-texture.png
(gnome-shell:4810): mutter-DEBUG: load_file: 2bdccc0: /usr/share/gnome-shell/theme/noise-texture.png
Gjs-Message: JS LOG: loading default theme (Adwaita)
(gnome-shell:4810): mutter-DEBUG: file_loaded: 2ae5300: /home/bellet/Documents/Meteosat/background.jpg 
(gnome-shell:4810): mutter-DEBUG: file_loaded: 2ae5580: /usr/share/backgrounds/gnome/adwaita-lock.jpg 
(gnome-shell:4810): mutter-DEBUG: file_loaded: 2bdccc0: /usr/share/gnome-shell/theme/noise-texture.png 
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_purge: 2ae5300: /home/bellet/Documents/Meteosat/background.jpg
Gjs-Message: JS LOG: _load=/home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_load: 30f1440: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_purge: 30f1440: /home/bellet/Documents/Meteosat/background.jpg
Gjs-Message: JS LOG: _load=/home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_load: 30f11c0: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_purge: 30f11c0: /home/bellet/Documents/Meteosat/background.jpg
Gjs-Message: JS LOG: _load=/home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_load: 30ba080: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_purge: 30ba080: /home/bellet/Documents/Meteosat/background.jpg
Gjs-Message: JS LOG: _load=/home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_load: 30b9dc0: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_purge: 30b9dc0: /home/bellet/Documents/Meteosat/background.jpg
Gjs-Message: JS LOG: _load=/home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_load: 2bdcc80: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_purge: 2bdcc80: /home/bellet/Documents/Meteosat/background.jpg
Gjs-Message: JS LOG: _load=/home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_load: 2bdc8c0: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_purge: 2bdc8c0: /home/bellet/Documents/Meteosat/background.jpg
Gjs-Message: JS LOG: _load=/home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_load: 32d8980: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: load_file: 30f11c0: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_purge: 32d8980: /home/bellet/Documents/Meteosat/background.jpg
Gjs-Message: JS LOG: _load=/home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: meta_background_image_cache_load: 32d8900: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: file_loaded: 30f11c0: /home/bellet/Documents/Meteosat/background.jpg (in_cache=0)
(gnome-shell:4810): mutter-DEBUG: load_file: 30f1440: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: load_file: 30ba080: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: load_file: 2bdcc80: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: file_loaded: 30f1440: /home/bellet/Documents/Meteosat/background.jpg (in_cache=0)
(gnome-shell:4810): mutter-DEBUG: file_loaded: 30ba080: /home/bellet/Documents/Meteosat/background.jpg (in_cache=0)
(gnome-shell:4810): mutter-DEBUG: file_loaded: 2bdcc80: /home/bellet/Documents/Meteosat/background.jpg (in_cache=0)
(gnome-shell:4810): mutter-DEBUG: load_file: 32d8980: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: file_loaded: 32d8980: /home/bellet/Documents/Meteosat/background.jpg (in_cache=0)
(gnome-shell:4810): mutter-DEBUG: load_file: 2bdc8c0: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: file_loaded: 2bdc8c0: /home/bellet/Documents/Meteosat/background.jpg (in_cache=0)
(gnome-shell:4810): mutter-DEBUG: load_file: 32d8900: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: load_file: 30b9dc0: /home/bellet/Documents/Meteosat/background.jpg
(gnome-shell:4810): mutter-DEBUG: file_loaded: 32d8900: /home/bellet/Documents/Meteosat/background.jpg 
(gnome-shell:4810): mutter-DEBUG: file_loaded: 30b9dc0: /home/bellet/Documents/Meteosat/background.jpg (in_cache=0)

You'll see the succession of meta_background_image_cache_load()/meta_background_image_cache_purge() for the same image. The file_loaded callback for this image occurs later, when this image is not needed anymory (when in_cache=0). This behaviour is related to this code in js/ui/background.js:305:

        let signalId = this._cache.connect('file-changed',
                                           Lang.bind(this, function(cache, changedFile) {
                                               if (changedFile == filename) {
                                                   let imageCache = Meta.BackgroundImageCache.get_default();
                                                   imageCache.purge(changedFile);
                                                   this.emit('changed');
                                               }
                                           }));

As I understand the case, even if there's no memory leak, this is problematic on a memory footprint point of view, because this unused texture can have an important size, and will stay until the JS GC has an opportunity to run. And this memory is not considered by the JS runtime when pondering the GC need, because it's part of an underlying g_objects, not a JS object ?
Comment 1 André Klapper 2015-04-14 19:52:15 UTC
Which gnome-shell version is this about? Please set the Version field. Thanks!
Comment 2 Cosimo Cecchi 2017-07-31 15:19:25 UTC
Created attachment 356652 [details] [review]
background: use of CHANGES_DONE_HINT events to avoid reloads

Instead of potentially loading a background mid-way when it changes, and
loading it again for every file monitor event, leverage
CHANGES_DONE_HINT events, which allow us to ignore CREATED and CHANGED
signals from the file monitor.

---

This is indeed still a problem; I tested the attached patch to fix it.
Comment 3 Florian Müllner 2017-07-31 23:50:32 UTC
Review of attachment 356652 [details] [review]:

LGTM
Comment 4 Cosimo Cecchi 2017-08-01 09:14:10 UTC
Attachment 356652 [details] pushed as a432653 - background: use of CHANGES_DONE_HINT events to avoid reloads