How to significantly reduce memory usage memory usage in GTK4 and libadwaita apps?

I have some low memory devices (with 4GB RAM), and GTK4 applications consume a lot of memory.

Examples:

  1. Even a hello world window may consume more than 100 mb of memory

  2. One app was reported to have a 3 fold memory increase after switching from GTK3 to GTK4.

Is there any workaround?

For GTK4 apps, one can set the environment variable GSK_RENDERER=cairo. It makes the apps stop using hardware acceleration (which is usually not available/not very powerful in most low-end devices anyway), but reduces the memory usage from 2-3 fold.

Examples:

  1. It was reported that it reduced one application’s memory usage from 100+ MB to 33MB.

  2. In my one of the apps I develop, memory usage reduced from 250+ mb to 140 mb after applying this.

How to apply this:

  1. If you want this for some particular app, edit its desktop file and replace Exec=env GSK_RENDERER=cairo app_executing_command.

  2. For flatpak apps, you can add environment variables with flatseal.

  3. Add GSK_RENDERER=cairo to .profile in your home folder.

  4. To do it system-wide for all users, add GSK_RENDERER=cairo to a new line in /etc/environment.


Source: https://github.com/gtk-rs/gtk4-rs/issues/1732