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

Memory usage skyrockets when doing anything in Pinta #939

Open
khoidauminh opened this issue Aug 12, 2024 · 5 comments
Open

Memory usage skyrockets when doing anything in Pinta #939

khoidauminh opened this issue Aug 12, 2024 · 5 comments
Labels
Milestone

Comments

@khoidauminh
Copy link
Contributor

khoidauminh commented Aug 12, 2024

To Reproduce

  1. In Pinta, select a brush/pencil tool and start drawing;
  2. Keep drawing and watch as its memory usage goes up.

It's also possible to cause the memory usage to go up by just zooming in and out of the canvas, selecting random places in the canvas, etc. But drawing usually drives the RAM usage up the most.

Additional Info

pinta.mp4

Commit that introduced this regression: #685

@khoidauminh khoidauminh changed the title Memory usuage skyrockets when drawing Memory usage skyrockets when drawing Aug 12, 2024
@khoidauminh khoidauminh changed the title Memory usage skyrockets when drawing Memory usage skyrockets when doing anything in Pinta Aug 12, 2024
@badcel
Copy link
Contributor

badcel commented Aug 12, 2024

Can Confirm on Fedora 40.

@cameronwhite
Copy link
Member

Confirmed on macOS as well.
If I launch Pinta with the --debug flag, which forces the GC to run very frequently (https://github.com/PintaProject/Pinta/blob/master/Pinta/Main.cs#L107) then I didn't observe any major memory growth, so that might be a good starting point for investigation

@cameronwhite cameronwhite added this to the 2.2 milestone Aug 13, 2024
@potatoes1286
Copy link
Contributor

potatoes1286 commented Aug 14, 2024

Debug flag does seem to fix it from me (I had been seeing >10GB ram usage just adding text!), however even with debug on it still experiences heavy >3GB ram spikes with accompanying lag spikes when zooming in extremely low.
image

@cameronwhite
Copy link
Member

That might be a somewhat separate issue - the canvas renderer isn't as efficient when zooming in after the port to GTK4 since we can't do partial redraws of only the visible area.
But it could also be related somewhat to the GC issue if the Cairo.ImageSurface used by the canvas isn't being collected quickly enough, since the Cairo.ImageSurface binding doesn't currently inform the GC about the native memory size it represents.

@cameronwhite
Copy link
Member

Just recording notes from my investigation:
Adding an explicit context.Dispose () at the end of PintaCanvas.Draw()

private void Draw (Cairo.Context context, int width, int height)
fixes the vast majority of the memory usage increase

This particular Cairo.Context likely has a big effect on memory usage since it can be the last reference to a temporary Cairo surface from the GTK widget (https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gsk/gskrendernodeimpl.c#L3495)

We can make this fix in Pinta once there's a new gir.core release with the fixes for gircore/gir.core#1109

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

No branches or pull requests

4 participants