-
Notifications
You must be signed in to change notification settings - Fork 128
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
Reduce memory usage by keeping main window out of memory #207
Comments
KeepassXC is a Qt C++ application. Vorta is PyQt (Python + Qt), which introduces some overhead. I did a quick memory profiling and most of it is allocated when loading the different Qt UIs. So one way to optimize would be to avoid creating/loading the main window unless it's actually opened. I tried this just now and memory usage went to 50MB. So that's surely an option. To reach the memory usage of C++, it would need rewriting in that or maybe Go. Can be done, but a big project and will lock many people out of contributing. On macOS I also noticed that RAM usage goes down a lot after starting it. I guess the OS moves some data to swap or compresses it.
|
How much of this is virt(ual), how much res(ident)? See columns in |
They call RES "Real Memory". I'm assuming VIRT is normal memory. There is also compressed memory. Columns in Looking at some other processes, we're not too terrible. Could still be lower if we manage to fully remove the main window from memory when it's not used. |
Can you try calling the gc after setupUI and after each tab is initialized? Part of the "problem" might be Python fetching memory from the OS, but being rather reluctant to give it back, but rather keeping free memory in its own memory management. As long as the memory is not actively used, it is maybe not as bad as it looks though. |
Like this? Not much difference. I think the main window including all references need to be fully removed when the window is closed.
|
Related: https://stackoverflow.com/questions/20164015/is-deletelater-necessary-in-pyqt-pyside Should be possible to recreate the window instead of hiding it when it's closed. I just worry about signals not being passed through. Will need some case-by-case adjustments. |
I mentioned KeepassXC just as an example, just because it was the first thing that hit me when looking at what app on my tray I could refer to. I was not suggesting a complete rewrite; I think that preventing the main window to load when not used, or running the program in a way similar to a daemon, could be a viable solution. |
Yeah. I also think cleaning up the main window from memory is a good step. I may look into rewriting it in Go at some point. Many things, like the UI files should be directly reusable anyways. |
Here a fairly small PR #208 that removes the main window from memory when closing it. With it, memory usage is about 70-80MB on macOS (10MB compressed memory) and Linux. With the window open, it increases to about 300MB, but goes down again on closing. |
If there aren't any complaints, I'll go ahead and merge this soon. So far I tested it under macOS and Ubuntu. No issues. The main window was fairly isolated except for a single call to refresh the time of the next scheduled backup. |
Merged this, since nobody complained. Please report any bugs that may appear in the master-branch. |
I have an issue with this fix. main_window attribute is not created when launched in background.
|
Probably true. The function |
Here a slightly changed function. Does this work? (I don't have KDE, so can't test it). The main window could be hidden OR closed.
|
Almost ok.
|
I see. You have the full stacktrace? Should be a quick fix too. Also thanks for testing this. |
The full stacktrace :
|
Here a new snippet:
|
My previous workflow seems to work. |
Great. Since this crashes it, I'll probably do another hotfix. Seems we had too many risky changes in the last release and people don't bother testing the master branch. |
Released as v0.6.15. |
Thx |
I'm reporting this from Linux (openSUSE Tumbleweed to be precise, if it matters).
On my system, Vorta uses about 215~220 MB of RAM when running, even when not performing any action and merely residing idle on the system tray.
This seems to be a bit high.
For comparison, KeepassXC uses about 25~30 kB; it is a different software, with a different purpose, but it behaves in a similar way: it resides on the tray when idle, and like Vorta it uses Qt.
The text was updated successfully, but these errors were encountered: