Root cause found, at least for the X11 + NVIDIA case. Reported upstream with
measurements and a reproducer:
https://gitlab.gnome.org/GNOME/gtk/-/issues/8582
Short version:
The GTK 4 file chooser (used by xdg-desktop-portal-gnome, which is what Chrome
and Firefox show) sets a tooltip on every list row. Each time, GTK looks up the
window under the pointer, and gdk_x11_device_xi2_surface_at_position() wraps
that lookup in XGrabServer()/XUngrabServer().
With the NVIDIA proprietary driver, each server grab costs 4-15 ms while
gnome-shell is redrawing. The Xorg main thread sleeps meanwhile. Without
NVIDIA, or on an idle screen, a grab costs ~0.01 ms. Loading a folder triggers
hundreds of grabs, so on my machine a folder of ~200 entries took 27 s to over
2 minutes.
Ubuntu 24.04.5, X11, GTK 4.14.5, NVIDIA 580.196.07, RTX 4090.
Wayland is not affected, because it has no server grabs. This would also
explain why removing xdg-desktop-portal-gnome (#18) helped some of you: the GTK
3 chooser in xdg-desktop-portal-gtk does not set per-row tooltips. In my
measurement it loads the same folders in 0-1 ms.
How to check whether you have the same problem: the issue above contains
a 30-line C program (grabcost.c) that measures the grab cost. Run it
while something on screen animates. If "with XGrabServer" shows several
ms instead of ~0.01 ms, this is your bug.
Workarounds. No package removal needed; both are per-user and easy to
undo.
A) Keep the GTK 4 dialog and disable the server grab only in the portal
process:
sudo apt install gcc libx11-dev
mkdir -p ~/.local/lib/gtk-nograb
~/.config/systemd/user/xdg-desktop-portal-gnome.service.d
printf '#include <X11/Xlib.h>\nint XGrabServer(Display *d){(void)d;return
1;}\nint XUngrabServer(Display *d){(void)d;return 1;}\n' > /tmp/nograb.c
gcc -shared -fPIC -O2 -o ~/.local/lib/gtk-nograb/libnograb.so /tmp/nograb.c
printf
'[Service]\nEnvironment=LD_PRELOAD=%s/.local/lib/gtk-nograb/libnograb.so\n'
"$HOME" > ~/.config/systemd/user/xdg-desktop-portal-gnome.service.d/nograb.conf
systemctl --user daemon-reload && systemctl --user restart
xdg-desktop-portal-gnome
The grab only guards against the pointer moving during the lookup, so dropping
it is harmless for this process. On my machine the GTK 4 widget then loads the
same folder in ~2 ms instead of 27 s. With the real portal dialog, Xorg went
from asleep 70 % of the time to 0 %.
To undo: delete nograb.conf, then run the daemon-reload and restart commands
again.
B) Use the GTK 3 chooser via config (the idea from #36). This needs no
compiler, but the dialog looks different. ~/.config/xdg-desktop-
portal/portals.conf should keep Ubuntu's other defaults:
[preferred]
default=gnome;gtk;
org.freedesktop.impl.portal.Secret=gnome-keyring;
org.freedesktop.impl.portal.FileChooser=gtk;
Then run: systemctl --user restart xdg-desktop-portal
I measured the GTK 3 chooser itself, but I did not test this portal config path
myself.
** Bug watch added: gitlab.gnome.org/GNOME/gtk/-/issues #8582
https://gitlab.gnome.org/GNOME/gtk/-/issues/8582
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2018539
Title:
File selector extremely slow
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gtk+3.0/+bug/2018539/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs