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

[Bug]: Long-running Tuba leaks memory #798

Closed
algernon opened this issue Feb 22, 2024 · 4 comments · Fixed by #799
Closed

[Bug]: Long-running Tuba leaks memory #798

algernon opened this issue Feb 22, 2024 · 4 comments · Fixed by #799
Labels
bug Something isn't working

Comments

@algernon
Copy link

Describe the bug

I usually leave my computer running for the night for various reasons, and as such, Tuba is left running too. I noticed that memory consumption is constantly growing, and reloading (Ctrl+R) my timeline does not seem to make any difference. As the memory use increases, responsiveness decreases too, although reloading the timeline seems to help with the responsiveness, at least.

I have to restart Tuba daily to keep things under control. Not a big deal, but a minor annoyance nevertheless.

Steps To Reproduce

  1. Start Tuba.
  2. Look at how much memory it is using.
  3. Leave it running for a day or two.
  4. Look at how much memory it is using again.

Logs and/or Screenshots

No logs yet, but next time I restart Tuba (after I finished writing this report), I'll start it with debug logs enabled.

I did take a few snapshots of memory usage, as shown in top, though:

startup (~08:57, 2024-02-21):
    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
3138849 algernon  20   0 2561464 345116 126940 S   0.0   1.1   0:03.74 .dev.geopjr.Tuba

night (~21:02, 2024-02-21):
    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
3138849 algernon  20   0 5771092   3.4g 147140 S   0.0  10.8  29:40.89 .dev.geopjr.Tuba

morning (~07:00, 2024-02-22):
    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
3138849 algernon  20   0 7795368   5.3g 148564 S   0.0  16.9  76:41.32 .dev.geopjr.Tuba

Instance Backend

glitch-soc

Operating System

NixOS 23.11

Package

Compiled manually

Troubleshooting information

os: NixOS 23.11 (Tapir)
prefix: /nix/store/rksykg3cwpi52c8l813aghbw5b1qlhj5-tuba-0.6.3+snapshot.2024-02-20
flatpak: false
version: 0.6.3 (production)
gtk: 4.12.5 (4.12.5)
libadwaita: 1.4.2 (1.4.2)
libsoup: 3.4.4 (3.4.4)
libgtksourceview: 5.10.0 (5.10.0)

My Tuba is compiled from 1933edf, but the problem existed before too (with 0.6.3 + #728 applied on top).

Additional Context

No response

@algernon algernon added the bug Something isn't working label Feb 22, 2024
@algernon
Copy link
Author

Small update: I have restarted my Tuba with G_MESSAGES_DEBUG=Tuba dev.geopjr.Tuba, but for the past ~hour, I only saw two warning messages, nothing else. It is running through a wrapper that makes it find stuff (because NixOS), but I verified that G_MESSAGES_DEBUG=Tuba is present in its environment nevertheless.

Do I need to compile Tuba with certain flags to have debug logs?

@GeopJr
Copy link
Owner

GeopJr commented Feb 22, 2024

Do I need to compile Tuba with certain flags to have debug logs?

No, latest glib versions seem to have broken it 🙃 🙃 Was wrong

I noticed that memory consumption is constantly growing, and reloading (Ctrl+R) my timeline does not seem to make any difference.

This feels like a regression, I'll take a closer look, thanks!

As the memory use increases, responsiveness decreases too, although reloading the timeline seems to help with the responsiveness, at least.

Okay this is a huge discussion which has been an issue since forever and don't think it's going to be resolved anytime soon. It has been blocking me from implementing most timeline related requests. I'll link below some places it has been discussed on but the TLDR is:
Timelines use ListBoxes to display the posts. ListBoxes are not meant to be filled with thousands of widgets as they all stay in memory (this is what causes the UI to 'lag' when there are too many posts in the timeline but 'unlag' when you refresh).

GTK4 introduced ListViews (mostly for Nautilus afaik). They are recycler views, re-using the same widgets as you scroll instead of generating new ones. That also means that they do not stay in memory as widgets like images get destroyed as you scroll. ListViews however have some big disadvantages:

  • You can't have multiple different widgets at the same time. For example on profiles, Tuba has a cover widget at the top with profile info and then post widgets below it. 2 different types of widgets.[1]
  • Accessibility. For some unknown to me reason, you can't tab cycle through complicated nested widgets.[2]

Some versions ago, I did convert everything to ListViews. I got over [1] by creating the widgets on the "binding" stage (which was terrible as it basically removed any benefit the recycler had). But after discovering the accessibility issues I just reverted it. It's not wroth it. Code for it still exists in Tuba behind a flag.

The main suggestion I've been given is to just create my own recycler view but that is going to take a while: https://tech.lgbt/@GeopJr/111762122652180106

#179 #500 #724 #504

(I've been very frustrated with this which might come across in some of my messages on the issues 😓)

@algernon
Copy link
Author

If I can provide more information or assistance, let me know, and I'll try my best to help!

@GeopJr
Copy link
Owner

GeopJr commented Feb 22, 2024

I found the main leak! Though it might not fix everything

(Vala lambdas sometimes self ref and cause the widgets to not be destroyed, 99% of all leaks are due to this 🤷)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants