[cairo] Cairo and layered application

Behdad Esfahbod behdad at behdad.org
Wed Mar 7 16:05:03 PST 2007


On Tue, 2007-03-06 at 17:16 -0500, Behdad Esfahbod wrote:
> On Tue, 2007-03-06 at 14:43 -0600, Boris Zbarsky wrote:
> > Behdad Esfahbod wrote:
> > >> Are you generally interested in data of this sort?  If there's something I can 
> > >> do to help improve cairo performance, I'd love to help.
> > > 
> > > Definitely.  Pass 'em on.  Specifically, I'm really interested in a call
> > > graph to malloc.  There's a lot we can do to drop those.
> > 
> > I'll try to get together a more exhaustive list, but in the meantime 
> > https://bugzilla.mozilla.org/show_bug.cgi?id=368018 is a decent example 
> > (16% of total pageload time is under malloc/free, most of it called from 
> > cairo).  Most of the other profiles I've seen look much like this, so it 
> > may be worth addressing this one and then reprofiling.
> >
> > I don't have a good way to generate pictorial call graphs, but as far as 
> > cairo calls to malloc in that testcase go (note that some of the 
> > callstacks might have stack frames skipped due to the profiler being 
> > used...):
> 
> Thanks.  The list really helps.  Fortunately all look very easy to
> optimize as I expected.  I just need a test case that gives
> malloc/realloc numbers so I can measure my progress.
> 
> One way would be to write a small .so that overrides malloc/realloc, and
> run perf suite against it.  If we were using glib, such stats were
> free...  Anyway, anyone taking this?

Hacked my own malloc() wrapper, and after disabling visibility
attributes and "#define static", finally got down to good numbers.  Here
is what I get for the pers suite for one iteration:

         TOTAL                   MALLOC                 REALLOC
     num        size         num        size         num        size
       1          12           1          12           0           0    FcBlanksCreate
       1          12           1          12           0           0    _cairo_ft_unscaled_font_map_create
       1          16           1          16           0           0    FT_New_Memory
       1          16           1          16           0           0    _cairo_xlib_surface_font_init
       1          32           1          32           0           0    _XrmInternalStringToQuark
       1          52           1          52           0           0    _cairo_toy_font_face_create
       1          68           1          68           0           0    FcConfigCreate
       1         128           1         128           0           0    FcBlanksAdd
       1         196           1         196           0           0    _cairo_ft_unscaled_font_create_for_pattern
       1         256           0           0           1         256    FcBlanksAdd
       1       1,032           1       1,032           0           0    _cairo_scaled_font_map_lock
       1       2,048           1       2,048           0           0    _XlcCreateLocaleDataBase
       1       2,048           1       2,048           0           0    _XrmInternalStringToQuark
       1       4,115           1       4,115           0           0    FcConfigParseAndLoad
       2          40           2          40           0           0    _cairo_cache_create
       2          56           2          56           0           0    FcLangSetCreate
       2         256           2         256           0           0    FcFontSetAdd
       2         584           2         584           0           0    _cairo_hash_table_resize
       2         608           2         608           0           0    _cairo_ft_scaled_font_create
       3          24           3          24           0           0    FcConfigFilename
       3          29           3          29           0           0    _XlcAddCT
       3          33           3          33           0           0    FcConfigFilename
       3          36           3          36           0           0    FcFontSetCreate
       3          65           3          65           0           0    FcStrCopyFilename
       4         128           4         128           0           0    FcConfigSubstituteWithPat
       4         128           4         128           0           0    FcMatrixCopy
       4         160           4         160           0           0    _create_trapezoid_mask
       5         100           5         100           0           0    _cairo_hash_table_create
       5         860           5         860           0           0    _cairo_hash_table_create
       7         112           7         112           0           0    FcStrSetCreate
       7       4,480           0           0           7       4,480    FcFontSetAdd
      14     838,448          14     838,448           0           0    _XAllocScratch
      19         152          19         152           0           0    FcStrListCreate
      22         352          22         352           0           0    FcPatternCreate
      24       1,626          24       1,626           0           0    FcStrPlus
      24       7,776          24       7,776           0           0    _cairo_gstate_clone
      27       2,556          27       2,556           0           0    _get_bitmap_surface
      46     519,792          46     519,792           0           0    XML_GetBuffer
      47         615          47         615           0           0    _XlcCreateDefaultCharSet
      48         384          48         384           0           0    _XlcAddCharSet
      48         990          48         990           0           0    _XlcCreateDefaultCharSet
      48       2,304          48       2,304           0           0    _XlcCreateDefaultCharSet
      50       1,631          50       1,631           0           0    _XlcAddCT
      52         208          52         208           0           0    _XrmDefaultInitParseInfo
      52         260          52         260           0           0    _X11TransConnectDisplay
      52         624          52         624           0           0    _XOpenLC
      52         832          52         832           0           0    XRenderFindDisplay
      52         832          52         832           0           0    _X11TransConnectDisplay
      52         936          52         936           0           0    _X11TransConnectDisplay
      52         988          52         988           0           0    _X11TransGetPeerAddr
      52       1,092          52       1,092           0           0    XOpenDisplay
      52       1,664          52       1,664           0           0    _cairo_xlib_screen_info_get
      52       1,872          52       1,872           0           0    XOpenDisplay
      52       2,080          52       2,080           0           0    _XPollfdCacheInit
      52       3,744          52       3,744           0           0    XAddExtension
      52       4,160          52       4,160           0           0    XOpenDisplay
      52       4,368          52       4,368           0           0    XOpenDisplay
      52       5,200          52       5,200           0           0    XkbUseExtension
      52       5,824          52       5,824           0           0    XOpenDisplay
      52      31,824          52      31,824           0           0    XOpenDisplay
      52      42,640          52      42,640           0           0    XRenderQueryFormats
      52      52,208          52      52,208           0           0    XRenderQueryFormats
      52      69,472          52      69,472           0           0    XOpenDisplay
      52     353,080          52     353,080           0           0    XOpenDisplay
      52     851,968          52     851,968           0           0    XOpenDisplay
      54       3,052          54       3,052           0           0    _render_glyph_outline
      56       5,152          56       5,152           0           0    _cairo_scaled_glyph_lookup
      88       5,632           0           0          88       5,632    _cairo_rectilinear_stroker_add_segment
      88       9,856          88       9,856           0           0    cairo_pattern_create_linear
     104         208         104         208           0           0    _XlcCreateLC
     104         208         104         208           0           0    _XlcResolveLocaleName
     104         884         104         884           0           0    XInitExtension
     104       2,080         104       2,080           0           0    _XlcCreateLocaleDataBase
     104       3,328         104       3,328           0           0    XauReadAuth
     104       3,640         104       3,640           0           0    _XlcFileName
     104       7,488         104       7,488           0           0    XInitExtension
     104      28,288         104      28,288           0           0    XOpenDisplay
     104      31,616         104      31,616           0           0    _XlcCreateLocaleDataBase
     104     212,992         104     212,992           0           0    _XlcCreateLocaleDataBase
     156       1,248         156       1,248           0           0    _XlcAddLoader
     200      18,400         200      18,400           0           0    cairo_pattern_create_for_surface
     304      20,672         304      20,672           0           0    cairo_create
     304      98,496         304      98,496           0           0    _cairo_gstate_create
     352       6,336           0           0         352       6,336    _cairo_pattern_add_color_stop
     418      13,376         418      13,376           0           0    _XlcSetConverter
     497       7,264         497       7,264           0           0    FcStrCopy
     712   1,877,056         712   1,877,056           0           0    qsort
     882      20,322         882      20,322           0           0    __strdup
    1920   1,228,800        1920   1,228,800           0           0    _cairo_pen_init_copy
    1920   1,413,120        1920   1,413,120           0           0    _cairo_hull_create
    1920   1,413,120           0           0        1920   1,413,120    _cairo_pen_add_points
    1944       7,776        1944       7,776           0           0    XGetImage
    1944     171,072        1944     171,072           0           0    XCreateImage
    2688     182,784        2688     182,784           0           0    _cairo_pixman_image_create_linear_gradient
    2688     290,304        2688     290,304           0           0    _cairo_pixman_image_create_radial_gradient
    2688     311,808        2688     311,808           0           0    _cairo_pixman_image_create_linear_gradient
    2688     311,808        2688     311,808           0           0    _cairo_pixman_image_create_radial_gradient
    3016     667,392        3016     667,392           0           0    _cairo_pen_init
   10038   1,124,256       10038   1,124,256           0           0    XCreateGC
   10672  27,343,136       10672  27,343,136           0           0    _cairo_image_surface_composite_trapezoids
   10728     386,208       10728     386,208           0           0    FbPixelsCreateForData
   12160   1,888,000       12160   1,888,000           0           0    _cairo_utf8_to_ucs4
   12160   9,196,800       12160   9,196,800           0           0    _cairo_scaled_font_text_to_glyphs
   15872     380,928       15872     380,928           0           0    _cairo_gradient_pattern_init_copy
   28380   7,719,360       28380   7,719,360           0           0    _cairo_xlib_surface_create_internal
   32972 160,212,808       32972 160,212,808           0           0    FbPixelsCreate
   35708   8,141,424       35708   8,141,424           0           0    _cairo_image_surface_create_for_pixman_image
   38136   8,265,792       38136   8,265,792           0           0    _cairo_bo_event_queue_init
   38136  45,461,856       38136  45,461,856           0           0    _cairo_bentley_ottmann_tessellate_polygon
   38136  66,126,336       38136  66,126,336           0           0    _cairo_bo_event_queue_init
   42428   1,446,338       42291   1,435,270         137      11,068    (other)
   43691   1,747,640       43691   1,747,640           0           0    _cairo_pixman_format_create_masks
   43700   5,069,200       43700   5,069,200           0           0    pixman_image_createForPixels
   45224     363,584       45224     363,584           0           0    _cairo_surface_fill_region
   49672   3,775,072       49672   3,775,072           0           0    _cairo_path_op_buf_create
   49696  26,040,704       49696  26,040,704           0           0    _cairo_path_arg_buf_create
   58864     470,912       58864     470,912           0           0    _cairo_freelist_alloc
   70104  62,266,368           0           0       70104  62,266,368    _cairo_polygon_grow_by
   74168   9,493,504       74168   9,493,504           0           0    _cairo_pattern_create_solid
   80088   9,610,560       80088   9,610,560           0           0    cairo_pattern_create_radial
  102216 320,289,920           0           0      102216 320,289,920    _cairo_traps_grow_by
  108832  28,188,672           0           0      108832  28,188,672    _cairo_spline_grow_by
  163052   3,035,932      163052   3,035,932           0           0    alloc_node_for_level
  682080   8,184,960      682080   8,184,960           0           0    _cairo_pixman_region_create_simple
 1927116 827,436,080     1643459 415,250,228      283657 412,185,852    (total)

> >    realloc
> >      cairo_polygon_add_edge
> >        cairo_polygon_line_to
> >          cairo_filler_line_to
> >            cairo_path_fixed_interpret
> >              cairo_path_fixed_fill_to_traps
> >                cairo_surface_fallback_fill
> >      cairo_traps_grow_by
> >        cairo_traps_add_trap
> >          cairo_traps_add_trap_from_points
> >            cairo_bentley_ottmann_tessellate_polygon
> >            cairo_bo_edge_end_trap
> >              cairo_bentley_ottmann_tessellate_polygon
> 
> Both realloc an array to fit more items, but oops!  they just enlarge it
> enough to fit the items at hand (I may be wrong, but I don't think I
> am.)  That means, at some point, they will realloc on any operation!
> 
> Easy-fix: exponentially enlarge them.

Seems like I was wrong.  It does do exponential growth.  Just in a weird
way.



-- 
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





More information about the cairo mailing list