The Case of The Curiously Slow Druid


The Setup

I've had this really curious and frustrating problem for a while now, my iteration loop while working on my Druid based fantasy map tool Lipuma has been horribly hampered by means of occasional massive startup times. In the order of tens of seconds.

When these account for around a third of the whole build time for the application, it can get extremely frustrating.

Early Troubleshooting

I had tried looking into this issue before to little avail. Perf/hotshot would get lost in the indirect calls made by GTK, but it was clear at least that it was a GTK issue. It was getting hung up somewhere in what looked like gtk_icon_theme_get_for_screen. However all avenues down that route seemed to be without much in the way of solutions.

After I identified that function as being the longest running one in the application that I could find at the time I was left frustrated. It says that it can be expensive to recalculate those symbols, so why is it doing so without me saying I need any of them!? However with no solution I left it be for the time, and let the sand it put in the gears just slow my motivation to work on Lipuma down.

According to old messages I left in the Recurse group chat, I apperently thought that This conversation had something to do with it, and tried changing my GTK theme. It didn't help.

New Discoveries

Today I took another crack at it. I've been trying to keep up with the recent development of Raph Levien's other Rust GUI projects and that had motivated me to start working on mine again. Immediately I was frustrated by the slow startup times even just for simple poking around.

I found this conversation which pointed me in the direction of journalctl. I would like to think I could be forgiven for not thinking to look in the system journal logs for a user desktop application issue. It seems crazy to me that the system logs would be the right place to put information like this, and not say, the terminal that the program opened in.

Looking into journalctl however I did notice multiple interesting things. A misbehaving usb device, (My cheap little webcam I found out), a user service that was looking for a program that no longer existed (A fail-restart count of over 20000!) and when opening my program and triggering the bug? A massive wall of text. goa-daemon letting me know that secret_password_lookup_sync() returned NULL, a bunch of GTK daemons being activated and /run/user directories failing to mount by fusermount, multiple portal services attempting to open, all until theres a timeout on org.freedesktop.secrets that has failed, with a timeout of 12 seconds... That sounds like some smoking guns.

I started googling around by copying some of these error messages until I found "[Solved] Slow launch of GTK3 apps with dbus-run-session"!!!!

Solved? Slow launch of GTK? That HAS to have what I need!

So I read down through it.

Uninstalling flatpack and probably xdg-desktop-portal will probably accelerate things.

No. No it cant be. How could it be flatpack? I dont use flatpack I hate flatpack. Its an answer in search of a problem. Its caused issues with incorrect versions of dependancies more times than its solved them.

sudo apt uninstall flatpack xdg-desktop-portal

Check the bug again.

Its solved.