Attached is a patch which will ensure every .object in a FcPattern has gone though FcStaticObjectName(), so that lookup can then be a binary search based on pointer compare rather than string compare. This saves both memory: before: still reachable: 1279114 bytes in 22542 blocks. after: still reachable: 1254887 bytes in 21980 blocks. but also processor cycles, as strcmp() is called far less: before: 42,567,584 ???:strcmp [/lib/tls/libc-2.3.2.so] after: 36,220,128 ???:strcmp [/lib/tls/libc-2.3.2.so] (from running callgrind on the GTK+ font selector)
Created attachment 2028 [details] [review] The patch
Obviously the next step is to find where the rest of the strcmp() are being called, and to possibly apply the same algorithm to *all* strings going into the patterns.
I did a quick hack which changed FcValueSave on strings from a call to FcStrCopy into call to FcObjectStaticName. Running fc-list with ~400 fonts in Valgrind gives me this. Before: malloc/free: 68325 allocs, 66665 frees, 3506738 bytes allocated. After: malloc/free: 59101 allocs, 57441 frees, 3376916 bytes allocated.
Created attachment 2274 [details] [review] Make pattern values static Applying both the first patch and this patch will result in all strings in patterns being made static. This helps as it reduces duplication of values: for example on my system there are 464 copies of the string "Adobe" and 330 copies of the string "Bold".
I've just committed the first patch, making the "object" variables static. I'll work on the values patch more, as I'm not happy with it.
Created attachment 2283 [details] [review] Make all values static This patch puts all FcPattern string values through FcObjectStaticName, and ignores strings when the values are being destroyed.
All .object values are now static after the mmap goodness.
Marking FIXED.
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.