Bug 2659

Summary: Perform pattern lookups without strcmp
Product: fontconfig Reporter: Ross Burton <ross>
Component: libraryAssignee: Keith Packard <keithp>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: high CC: bugzilla
Version: 2.2   
Hardware: x86 (IA32)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: The patch
Make pattern values static
Make all values static

Description Ross Burton 2005-03-07 04:06:45 UTC
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)
Comment 1 Ross Burton 2005-03-07 04:07:04 UTC
Created attachment 2028 [details] [review]
The patch
Comment 2 Ross Burton 2005-03-07 04:10:53 UTC
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.
Comment 3 Ross Burton 2005-03-30 07:03:45 UTC
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.
Comment 4 Ross Burton 2005-03-31 08:22:03 UTC
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".
Comment 5 Ross Burton 2005-03-31 11:17:33 UTC
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.
Comment 6 Ross Burton 2005-04-01 04:24:14 UTC
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.
Comment 7 Patrick Lam 2006-02-22 02:05:02 UTC
All .object values are now static after the mmap goodness.
Comment 8 Patrick Lam 2006-02-22 02:05:18 UTC
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.