Re: Realloc called too often in FcCharSetPutLeaf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2008-02-14 at 17:38 +0100, Michal Novotny wrote:
> Hi,
> 
> I was looking at performance of FireFox3 startup using callgrind and 
> found a lot of calls to realloc() from FcCharSetPutLeaf(). During the 
> startup there are 10 calls to FcFontSort() that lead to 105242 calls to 
> FcCharSetPutLeaf() and 209842 calls to realloc(). I tried to 
> allocate/reallocate memory in bigger blocks and calls to realloc() were 
> reduced to 25982 when block size was 8 (patch is attached). Of course 
> some memory is wasted with this approach but number of instructions 
> needed to do FcFontSort() decreased from 176569552 to 125762052. Is it 
> possible to have similar optimalization in next releases of fontconfig?

Yeah, this is consistent with my observations.  I wanted to look into it but you beat me to it.  For the record, doing a Pango "hello world" using the following command:

  pango-view --text "hello world"

produces the following memory statistics (using my malloc-stats tool available in cairo/util):


	 TOTAL			 MALLOC			REALLOC
     num	size	     num	size	     num	size

[...]
      10         160	      10         160	       0           0	*INT_cairo_font_options_create()
      10         960	      10         960	       0           0	_cairo_hash_table_create()
      10      24,971	      10      24,971	       0           0	XOpenDisplay()
      12       1,716	      12       1,716	       0           0	_nl_intern_locale_data()
      12       4,224	      12       4,224	       0           0	__fopen_internal()
      15         205	      15         205	       0           0	strdup()
      16         250	      16         250	       0           0	__nss_database_lookup()
      16       1,472	      16       1,472	       0           0	_cairo_scaled_glyph_lookup()
      19         730	      19         730	       0           0	nss_parse_service_list()
      22      17,024	       4         512	      18      16,512	FcFontSetAdd()
      27         864	      27         864	       0           0	_XlcSetConverter()
      27       5,756	      27       5,756	       0           0	_XkbReadGetMapReply()
      31         748	      18         560	      13         188	_XlcParse_scopemaps()
      32       1,372	      32       1,372	       0           0	_nl_make_l10nflist()
      34      12,904	      34      12,904	       0           0	xcb_send_request()
      35       1,332	      35       1,332	       0           0	FcConfigHome()
      41       1,120	      41       1,120	       0           0	FcNameRegisterConstants()
      51       1,700	      51       1,700	       0           0	FcCacheCopySet()
      52         416	      52         416	       0           0	FcStrListCreate()
      52         416	      52         416	       0           0	_XlcAddCharSet()
      53       1,660	      53       1,660	       0           0	_XlcAddCT()
      54       3,891	      46       3,371	       8         520	vasprintf()
      57       1,697	      57       1,697	       0           0	FcStrSetAdd()
      60       4,047	      60       4,047	       0           0	FcStrPlus()
      66      68,112	      66      68,112	       0           0	XML_GetParsingStatus()
     122      10,208	     122      10,208	       0           0	FcStrSetDel()
     132       2,112	     132       2,112	       0           0	FcCharSetCreate()
     134       3,752	     134       3,752	       0           0	FcLangSetCreate()
     136       4,352	     136       4,352	       0           0	FcConfigSubstituteWithPat()
     144      78,722	     125      72,738	      19       5,984	FT_New_Memory()
     155       4,241	     155       4,241	       0           0	_XlcCreateDefaultCharSet()
     268      10,720	     268      10,720	       0           0	XML_ParserCreate()
     271       4,336	     271       4,336	       0           0	cairo_font_options_copy()
     277      33,810	     277      33,810	       0           0	IA__g_malloc0()
     290       3,669	     276       3,194	      14         475	_XlcDestroyLocaleDataBase()
     290      54,528	     154      19,712	     136      34,816	FcPatternHash()
     336       5,057	     336       5,057	       0           0	FcConfigFilename()
     347       5,581	     346       5,533	       1          48	XrmGetResource()
     477      12,773	     477      12,773	       0           0	FcPatternCreate()
     593     849,534	     593     849,534	       0           0	XML_GetBuffer()
     637       9,754	     637       9,754	       0           0	FcStrCopy()
     647     199,620	       0           0	     647     199,620	IA__g_realloc()
     729       8,338	     729       8,338	       0           0	FcStrSetCreate()
    1001      68,832	    1001      68,832	       0           0	IA__g_malloc()
    2599   1,695,090	    2599   1,695,090	       0           0	_hb_alloc()
    3766      75,320	    3766      75,320	       0           0	FcValueSave()
    6512     194,132	    6498     191,572	      14       2,560	FcStrSetAddFilename()
  124902  50,686,656	   41898   1,333,080	   83004  49,353,576	FcCharSetNew()
  145776  54,395,761	   61893   4,776,114	   83883  49,619,647	(total)

As can be seen, fontconfig is responsible for most of the malloc and
realloc calls!  I may look into this later, but for now, fixing the
realloc problem you identified is the biggest step.

> Michal

-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759

_______________________________________________
Fontconfig mailing list
Fontconfig@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/fontconfig

[Index of Archives]     [Fedora Fonts]     [Fedora Users]     [Fedora Cloud]     [Kernel]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Gimp Graphics Editor]     [Yosemite News]

  Powered by Linux