[Fontconfig] Application startup performance

Patrick Haller patrick.haller at haller-consult.de
Fri Jan 8 18:24:25 PST 2016


Hi,

Profiling application startup performance, I noticed that libfontconfig 
accounted for a significant portion of the startup time, approx. 30% for 
a rather simple application like gedit.

My font directories, especially /usr/share/fonts/100dpi and 
/usr/share/fonts/75dpi contain each 1900 files after a default gentoo 
installation of X.org, residing on local storage.

I found two rather small optimizations to improve the startup time:
- assuming that readdir() will never return duplicate filenames within 
the very same directory. Hence FcStrSetAdd() can spare the duplicate 
check, which currently runs FcStrCmp() along a growing linear list of 
filenames. In fact, I have not found any duplicate string being entered 
to a FcStrSet at all for my system configuration.
- _FcStrSetAppend() to not reallocate and memcmp element by element, but 
doing so for e. g. 64 elements at a time.

I've verified startup time using
- time gedit (average over 9 runs)
- callgrind and cachegrind
- oprofile


Applied optimizations:
- skip duplicate check in FcStrSetAppend for values originating from 
readdir()
- grow FcStrSet in 64-element bulks for local FcStrSets (FcConfig layout 
unaltered)

Starting gedit is measured to

                         Unoptimized     Optimized
user[s]                         0,806         0,579
sys[s]                          0,062         0,062
Total Instr Fetch Cost: 1.658.683.750   895.069.820
Cachegrind D Refs:        513.917.619   312.000.436
Cachegrind Dl Misses:       8.605.632     4.954.639


The patch is attached. Comments and questions are welcome.

Thanks,
Patrick

-- 
--
Patrick Haller (patrick.haller at haller-consult.de)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Optimizations-in-FcStrSet.patch
Type: text/x-patch
Size: 6379 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/fontconfig/attachments/20160109/6e3c0d89/attachment.bin>


More information about the Fontconfig mailing list