[Fontconfig] Fontconfig performance question.

Krzysztof Dabrowski fontconfig@fontconfig.org
Fri, 9 May 2003 10:04:13 +0200


Here comes my idea (and the format will be structure independant + ultra fast 
to load).

Saving the cache to disk will require significant amount of work but loading 
and re-using it should be blazing fast..

The whole idea is to 


a) compute the total memory consumption of a given structure including all 
it's members and members' members etc.
b) allocate a single block of memory of desired lenght.
c) make a copy of the structure to this block changing it to occupy the linear 
space without gaps.
d) scan the structure for ALL POINTERS, convert them to be relative to the 
block's begining and output pointer location to a list.
e) save the area together with pointers addreses lists to a binary file.


a) read cache file header.
b) malloc the structure area in one single malloc
c) read the structure inside this are
d) read pointers' addresses from the file
e) perform address fixing (convert pointers from relative to absolute).
f) and here we have the structure as it was before..

The SAVE part looks a bit complicated but points a,b,c could be made 
transparent by using a malloc replacement that works in a static 
pre-allocated buffer (there is something called amalloc on some unixes)..

And i think that if the first element of the structure will be the structure's 
address and we'll make sure that the main structure is the first thing 
allocated in the buffer (so structures address == buffer address) then we 
could even skip d) and e) and the loader that has knowledge of the structure 
format will be able to recursiveli traverse it and "fix" all the pointers but 
this would slow loading a bit.

And about versioning: such things like this cache can be in my opinion realy 
library-version dependant, if the cache is from older version, re-creating it 
takes just a second or two..

Now i'm waiting for your input. If somebody know how to make point d) in the 
SAVE easly then i think the whole thing can make sense.