Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for "cleaning" the images from ram #28

Open
JustSimplyKyle opened this issue Sep 22, 2022 · 6 comments
Open

Support for "cleaning" the images from ram #28

JustSimplyKyle opened this issue Sep 22, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@JustSimplyKyle
Copy link

Currently(at least from what I've observed), swww will put every image you load into ram, which is not great since I change my wallpapers quite commonly
I hope that there could be a subcommand that will "clean" everything except the currently loaded wallpaper
Maybe sth like cleancache

@JustSimplyKyle
Copy link
Author

It seems like swww would sometimes clean the ram when its usage get too high

@LGFae
Copy link
Owner

LGFae commented Sep 22, 2022

Yes, this is annoying, I agree, but unfortunately, I don't think there is anything we can do about it. Rust frees the img vector once it goes out of scope, meaning the memory will be given back to the OS, but it is up to it, the OS, to actually reclaim it. I looked up into this some time ago and there was basically nothing realistic we could go.

See, for example, this SO question for more details.

Writing a bunch of code for this is not something I am currently interested in. It could potentially involve looking into the image crate's internal, which would greatly increase our maintenance burden (since we would have to always keep track of changes in image crate's internal code and adapt accordingly).

In my experience, RAM usage will rarely go beyond 250MB, even when cycling through many images in a directory. Ultimately, I decided this was good enough.

However, it is indeed very unfortunate, since during development I managed to reduce the memory usage to just ~35MB even with a 450 frames 1920x1080 gif. But the problem was, I would change something completely unrelated to the memory usage, and it would pretty much double, because that would cause a cascade of changes that would eventually lead to the OS taking longer to reclaim memory.

I will leave this open for now, because it might be that there is a way, and I am just not aware of it. Regardless, I am afraid you should think of this as a very long-term goal.


It seems like swww would sometimes clean the ram when its usage get too high

For the record, how much is this "too high" threshold for you?

@JustSimplyKyle
Copy link
Author

It sometimes cleans it at 200MB, but sometimes it would clean it at about 350MB instead
Anyway, I understand your concerns, I could just kill swww whenever I'm doing some memory intense work

@LGFae LGFae added the enhancement New feature or request label Oct 3, 2022
@LGFae
Copy link
Owner

LGFae commented Nov 28, 2022

Update: I have thought of something that might improve the situation. Currently, we send the image's filename to the daemon, and open and decode it there. We could instead open and decode the image in the client, send it to the daemon via socket, and just play the transition / animation there. This would mean the daemon won't have to allocate memory to decode the image. I don't know in practice if this will make a huge difference, but we can try it.

Also, in the beginning of development I decided to make everything one huge binary because it was convenient, but we could also make memory usage go down by separating the client and the daemon in two separate programs.

@LGFae
Copy link
Owner

LGFae commented Dec 10, 2022

I am about to merge PR #57. If it's not too much trouble, could you try out the separate-client-and-daemon branch and see if, indeed, memory usage also goes down in general for you?

Note that, after compiling, you will have to run the daemon manually: ./target/release/swww-daemon (instead of ./target/release/swww init). Alternatively, you can put the swww-daemon binary in your PATH.

@JustSimplyKyle
Copy link
Author

Works pretty well!
The memory usage mostly stayed around 100M, and never went higher than 200M
In a word, my memory usage has been cut in half!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants