SUMMARY When browsing directories with restricted (unreadable) subdirectories, such as /tmp, the KDE file dialog has major UI lags if the system has many groups. This affects file pickers in KDE and Qt apps, as well as the XDG portal. This is caused by repeated calls to KUser::groups from the paint code, which calls getgrouplist, which has to read and parse /etc/group and /etc/group.cache over and over again. See the attached flame graph. $ cat /etc/group.cache | wc -l 27634 $ du -h /etc/group.cache 752K /etc/group.cache There should be no need for this: getgrouplist's result can be cached and reused for the duration of the dialog's execution. STEPS TO REPRODUCE 1. Build KIO with tests 2. Run https://invent.kde.org/frameworks/kio/-/blob/master/tests/kfilewidgettest_gui.cpp 3. Navigate to /tmp or / OBSERVED RESULT Moving the mouse over restricted subdirectories (with the lock emblem) causes UI freezes. EXPECTED RESULT No UI slowdowns. SOFTWARE/OS VERSIONS KDE Frameworks Version: 6.11, 6.14 ADDITIONAL INFORMATION Relevant code: * KFileItem::isReadable: https://invent.kde.org/frameworks/kio/-/blob/85ac29eda6/src/core/kfileitem.cpp?page=2#L1292 * KUser::groups: https://invent.kde.org/frameworks/kcoreaddons/-/blob/f67da202b88231/src/lib/util/kuser_unix.cpp#L328
Created attachment 181350 [details] Flame graph (problematic calls have a blue outline)
(In reply to Ilya Bizyaev from comment #0) > SUMMARY > When browsing directories with restricted (unreadable) subdirectories, such > as /tmp, the KDE file dialog has major UI lags if the system has many > groups. This affects file pickers in KDE and Qt apps, as well as the XDG > portal. > > This is caused by repeated calls to KUser::groups from the paint code, which > calls getgrouplist, which has to read and parse /etc/group and > /etc/group.cache over and over again. See the attached flame graph. > > $ cat /etc/group.cache | wc -l > 27634 > $ du -h /etc/group.cache > 752K /etc/group.cache > > There should be no need for this: getgrouplist's result can be cached and > reused for the duration of the dialog's execution. IMO it should just use access(R_OK) instead. Apparently this behaviour of trying to handle permission checks in KIO code was introduced by https://invent.kde.org/frameworks/kio/-/merge_requests/1221, ironically with the motivation to avoid stat() calls.
$ cat /etc/group.cache | wc -l 27634 $ du -h /etc/group.cache 752K /etc/group.cache That's proper system stress testing. > IMO it should just use access(R_OK) instead. That's a good idea, re implementing this logic wasn't a particular great idea.
Just for reference, this bug makes the file picker almost unusable on my system. I have a similar setup as Ilya with logs of groups on my system. Is there a chance that someone could look at this in the near future? Thanks a lot!