After doing a few speed measurements to a Qt based program I found that
freetype was producing a few hotspots, two of them in src/smooth/ftsmooth.c

With the patch attached the time spent there was reduced some 50% (by
block re-allocations and more effective initialization). Perhaps you'll
find it worthwhile for mailine integration.

Regards,
/Mikko
diff --git a/src/smooth/ftsmooth.c b/src/smooth/ftsmooth.c
index 2e37b46..f719c15 100644
--- a/src/smooth/ftsmooth.c
+++ b/src/smooth/ftsmooth.c
@@ -1850,8 +1850,8 @@
       strategy_use_m_control = TRUE;
 
     /* Allocate */
-    segments
-      = (Stem_Segment*) malloc( (1) * sizeof ( Stem_Segment ) );
+    segments = NULL;
+/*      = (Stem_Segment*) malloc( (1) * sizeof ( Stem_Segment ) ); */
     leftmost_segment
       = (Stem_Segment*) malloc( sizeof ( Stem_Segment ) );
     leftmost_segment_not_extrema
@@ -1865,22 +1865,25 @@
     possible_stems = (Stem*) malloc ( MAX_STEMS * sizeof ( Stem ) );
     leftmost_stem  = (Stem*) malloc ( sizeof (Stem));
     rightmost_stem = (Stem*) malloc ( sizeof(Stem));
-    centers        = (Stem_Center*) malloc ( (1) * sizeof ( Stem_Center ) );
+    centers        = NULL;/*(Stem_Center*) malloc ( (1) * sizeof ( Stem_Center ) );*/
 
     if ( verbose )
       printf("\n");
 
     /* Initialize */
-    for ( xx = 0; xx < width * 256; xx += 1 )
-      stem_centers[xx] = 0;
 
+    memset( stem_centers, 0, width * 256*sizeof(stem_centers[0]) );
+/*
+    for ( xx = 0; xx < width * 256; xx += 1 )
+        stem_centers[xx] = 0;
+num_segments==0
     for ( xx = 0; xx < num_segments; xx += 1 )
     {
       segments[xx].x1 = 0;
       segments[xx].x2 = 0;
       segments[xx].y = 0;
     }
-
+*/
     rightmost_segment->x1 = 0;
     rightmost_segment->x2 = 0;
     rightmost_segment->y  = 0;
@@ -1902,9 +1905,10 @@
       /* Calculate various sums and stem widths of glyph */
       for ( xx = 0; xx < width; xx += 1 )
       {
-        /* Reallocate */
-        segments = (Stem_Segment*) realloc
-          ( segments, ( num_segments + 1 ) * sizeof ( Stem_Segment ) );
+        /* Reallocate (in blocks of 64) */
+        if( num_segments % 64 == 0 )
+            segments = (Stem_Segment*) realloc
+                ( segments, ( num_segments + 64 ) * sizeof ( Stem_Segment ) );
 
         /* if line is white, and now has color, it's the start of a stem */
         if ( current_value == 0 && line[xx] > 0 )
@@ -1929,9 +1933,10 @@
           stem_center_x = ( segments[num_segments].x2
                             + segments[num_segments].x1 ) / 2;
 
-          /* Reallocate */
-          centers = (Stem_Center*) realloc
-            ( centers, ( num_centers + 1 ) * sizeof ( Stem_Center ) );
+          /* Reallocate (in blocks of 32) */
+          if( num_centers % 32 == 0 )
+              centers = (Stem_Center*) realloc
+                  ( centers, ( num_centers + 32 ) * sizeof ( Stem_Center ) );
           centers[num_centers].x = stem_center_x;
           centers[num_centers].y = h;
           centers[num_centers].x1 = segments[num_segments].x1;
_______________________________________________
Freetype-devel mailing list
Freetype-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/freetype-devel

Reply via email to