GNOME Bugzilla – Bug 747794
background reloaded more than necessary
Last modified: 2017-08-01 09:14:23 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 ?
Which gnome-shell version is this about? Please set the Version field. Thanks!
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.
Review of attachment 356652 [details] [review]: LGTM
Attachment 356652 [details] pushed as a432653 - background: use of CHANGES_DONE_HINT events to avoid reloads