LGFae / swww

A Solution to your Wayland Wallpaper Woes
GNU General Public License v3.0
2.26k stars 67 forks source link

Feature Request: Optionally Cache Static Images in Memory #175

Open tyush opened 1 year ago

tyush commented 1 year ago

Hello,

I'm using swww for my desktop. I have a script that rapidly (anywhere from 1 to 8 times a second) asks the daemon to change the wallpaper between 3 images at varying speeds.

However, swww takes significant power trying to re-read the entire image from disk every swap even when they haven't changed.

Proposed Feature

Add two flags to the swww img command: --cache and --update-cache.

Wallpapers loaded using the --cache flag have the image read from a cache in memory, only reading from the file system if the image is not in the cache. Using the --update-cache option forces the image to be read from the file system, updating the image or adding it to the cache.

No change is made to program behavior not involving these flags. swww itself does not track files for changes.

LGFae commented 9 months ago

Ah, sorry, this sounds way too complicated. I know that at a high level it seems simple, but we would have to change a lot of things to implement it. For example, we couldn't just cache their bytes, we would also need to keep, at a minimum, their width, height and filename, since we can only use them if all of those match. Things can get annoying with multiple monitors configurations, at varying scale factors, etc.

Also, more importantly, I am trying to get memory usage down, not up. This would go completely against that.

To get what you want, may I suggest creating a gif with those 3 images? You can control their framerate during their creation. ffmpeg can be used for it.

To get something a little randomized (if that's what you want) your script can try recreating the gif every once in a while with different random framerates.

Aurillium commented 5 months ago

My use case for this is that I have a different wallpaper for each workspace and want to speed up the transition between wallpapers (right now it's quite slow) when I change workspaces. To prevent most people's RAM usage being increased the feature could only be enabled when a certain option is passed to the daemon and only added to with a --cache argument to swww img?

If I have enough spare time (not likely for a while) I'm happy to try implement this myself and submit a PR. If you don't want that though do you have any recommendations on how to solve the issue without modification? I've tried copying the files to a RAM filesystem on load but I haven't noticed any difference

LGFae commented 5 months ago

I am thinking of maybe implementing this using temporary files. That way, we wouldn't be using RAM. It would still be some ways off though.

If you don't want that though do you have any recommendations on how to solve the issue without modification?

Try swww img --transition-type=none. The transition will finish instantly. But note that decoding the image takes quite a while, so it might still not be fast enough.

I've tried copying the files to a RAM filesystem on load but I haven't noticed any difference

Right. Reading the files is not the problem; decoding them is. Decoding is currently the slowest part of the pipeline to get something to the daemon when you call swww img.