Bug 378227 - KDialog scans all fonts directory before showing dialog box making it super slow
Summary: KDialog scans all fonts directory before showing dialog box making it super slow
Status: RESOLVED NOT A BUG
Alias: None
Product: kdialog
Classification: Applications
Component: general (show other bugs)
Version: 1.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Brad Hards
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-29 06:39 UTC by Deepak Mittal
Modified: 2017-06-13 11:45 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Deepak Mittal 2017-03-29 06:39:50 UTC
I used strace and found out kdialog scans all my fonts directory before launching. If there are tons of fonts, it sometimes takes upto 10-15 seconds to show up. This is on a SSD, I can only imagine how slow it would be on an HDD.

I noticed these files take up tons of stat calls:
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/mdotbelow.glif", {st_mode=S_IFREG|0644, st_size=224, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/mediumshade.glif", {st_mode=S_IFREG|0644, st_size=19674, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/mhook.glif", {st_mode=S_IFREG|0644, st_size=2098, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/minus.glif", {st_mode=S_IFREG|0644, st_size=332, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/minusbelowcmb.glif", {st_mode=S_IFREG|0644, st_size=427, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/mlonglegturned.glif", {st_mode=S_IFREG|0644, st_size=1709, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/mturned.glif", {st_mode=S_IFREG|0644, st_size=387, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/mu.glif", {st_mode=S_IFREG|0644, st_size=1523, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/mu.math.glif", {st_mode=S_IFREG|0644, st_size=176, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/multiply.glif", {st_mode=S_IFREG|0644, st_size=657, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/musicalnotedbl.glif", {st_mode=S_IFREG|0644, st_size=1513, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/n.glif", {st_mode=S_IFREG|0644, st_size=1199, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/n.sups.glif", {st_mode=S_IFREG|0644, st_size=952, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/nacute.glif", {st_mode=S_IFREG|0644, st_size=218, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/naira.glif", {st_mode=S_IFREG|0644, st_size=1250, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/napostrophe.glif", {st_mode=S_IFREG|0644, st_size=1020, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/nbspace.frac.glif", {st_mode=S_IFREG|0644, st_size=110, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/nbspace.glif", {st_mode=S_IFREG|0644, st_size=128, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/ncaron.glif", {st_mode=S_IFREG|0644, st_size=218, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/ncommaaccent.glif", {st_mode=S_IFREG|0644, st_size=229, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/ndotaccent.glif", {st_mode=S_IFREG|0644, st_size=226, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/ndotbelow.glif", {st_mode=S_IFREG|0644, st_size=224, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/ngrave.glif", {st_mode=S_IFREG|0644, st_size=218, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/nhookleft.glif", {st_mode=S_IFREG|0644, st_size=1551, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/nine.cap.glif", {st_mode=S_IFREG|0644, st_size=1516, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/nine.dnom.glif", {st_mode=S_IFREG|0644, st_size=1519, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/nine.glif", {st_mode=S_IFREG|0644, st_size=1535, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/nine.numr.glif", {st_mode=S_IFREG|0644, st_size=176, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/nine.onum.glif", {st_mode=S_IFREG|0644, st_size=1521, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/nine.subs.glif", {st_mode=S_IFREG|0644, st_size=1527, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/nine.sups.glif", {st_mode=S_IFREG|0644, st_size=176, ...}) = 0
stat("/usr/share/fonts/opentype/scp/Roman/ExtraLight/font.ufo/glyphs/nje.glif", {st_mode=S_IFREG|0644, st_size=1467, ...}) = 0

This is from strace -C:

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 64.26    0.004864          14       344           getdents
 32.37    0.002450           0     49834       340 stat
  0.75    0.000057           0       139           brk
  0.54    0.000041           0      1253        24 lstat
  0.45    0.000034           0      1120       888 recvmsg
  0.33    0.000025           0       852        61 open
  0.33    0.000025           0       838           fstat
  0.28    0.000021           0      1140       553 access
  0.25    0.000019           0       337           mmap
  0.22    0.000017           0       799           close
  0.21    0.000016           0       142           fcntl
---snipped---
Comment 1 Christoph Feck 2017-04-21 17:17:08 UTC
Are you sure the 50000 stat calls are from /usr/share/fonts? Qt should only ask fontconfig to parse the font database once.

What you might see are stat calls for the icon themes.
Comment 2 Deepak Mittal 2017-06-10 08:30:42 UTC
Yes pretty sure. This doesn't just happen on dialog boxes, so you may change the "product" for this bug. This happens with every KDE application. I thought dolphin and gwenview were generally slow, but when I moved bulk of my fonts outside of /usr/share/fonts, everything became snappy. 

Every KDE application is parsing the fonts directory, which is making the system unusably slow.

This is first few lines from strace -C dolphin:
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 55.31    0.000521           1       850           getdents
 17.52    0.000165           0     55772      5920 stat
  7.11    0.000067           0     24605       127 lstat
  5.20    0.000049           0     11790           read
  4.46    0.000042           0      6217           close
  3.93    0.000037           0      7943      1735 open
  3.61    0.000034           0      6343      1654 readlinkat
  1.06    0.000010           0     11007           fstat
  0.85    0.000008           0      3742       359 access
  0.53    0.000005           0      2277           getrandom
  0.42    0.000004           0      1277           lseek
  0.00    0.000000           0      1299           write
  0.00    0.000000           0       802           poll
  0.00    0.000000           0       597           mmap
  0.00    0.000000           0       358           mprotect
  0.00    0.000000           0       111           munmap
  0.00    0.000000           0        67           brk
  0.00    0.000000           0        10           rt_sigaction
  0.00    0.000000           0         2           rt_sigprocmask
  0.00    0.000000           0        54           ioctl
  0.00    0.000000           0       453           writev
  0.00    0.000000           0        15           select

Bulk of the stat calls are because of the fonts in /usr/share/fonts.

I saved the strace output in /tmp/dolphin and then ran:
grep 'usr/share/fonts' /tmp/dolphin | wc -l                                                                                                                                 ⏎
47834

Clearly it's a big issue and it needs to be fixed.
Comment 3 Deepak Mittal 2017-06-10 08:32:49 UTC
Also see this:
grep 'usr/share/fonts' /tmp/dolphin | grep '^stat' | wc -l
47570
Comment 4 Deepak Mittal 2017-06-10 08:35:39 UTC
Someone else having the same issue here:
https://forums.opensuse.org/showthread.php/519936-Installing-new-fonts-in-Plasma-5-left-me-with-a-very-slow-system
Comment 5 Rex Dieter 2017-06-11 12:01:44 UTC
In contrast, for me:

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 20.56    0.004742           3      1678       298 stat
 11.91    0.002747           2      1144       480 access
 10.59    0.002444           3       790       657 recvmsg
  9.94    0.002294           2      1101        30 lstat
  7.84    0.001809           4       464        33 open

For me, the only fonts that get opened are the ones actually *used* in the dialog.

Otherwise, I also see lots of hits for stuff like:
open("/var/cache/fontconfig//711dae798b6bff4224ea2776edcb5c93-le64.cache-7", O_RDONLY|O_CLOEXEC) = 6
which is obviously a fontconfig cache.

If I had to speculate, one possibility is your fontconfig cache either doesn't exist or is invalidated (old?).  Maybe try running (as root):
fc-cache -sf
Comment 6 Deepak Mittal 2017-06-12 07:38:25 UTC
`sudo fc-cache -sf` didn't help. It's still making 55k stat calls in the /usr/share/fonts directory.
Comment 7 Deepak Mittal 2017-06-13 08:22:10 UTC
This somehow looks similar to this bug is also affecting inkscape and GIMP - https://bugs.launchpad.net/ubuntu/+source/fontconfig/+bug/1614870
Comment 8 Deepak Mittal 2017-06-13 10:33:58 UTC
On further investigation of strace output, and doing some grepping and filtering I found out the stat calls were made because of .glif files in /usr/share/fonts directory. All of these files were basically sources of source-code-pro font (https://github.com/adobe-fonts/source-code-pro). I deleted the entire directory of that font and that has fixed the problem. I'll file this bug with them and recommend them to not store source glyph files in the /usr/share/fonts.

You can close this bug. Thankyou!
Comment 9 Christoph Feck 2017-06-13 11:45:57 UTC
Thanks for the update; closing.