[line-map] simple oneliner that speeds up track-macro-expansion

Dimitrios Apostolou jimis@gmx.net
Tue Jun 5 00:49:00 GMT 2012


Hi Dodji,

On Mon, 4 Jun 2012, Dodji Seketeli wrote:

> Hello Dimitrios,
>
> I cannot approve or deny your patch, but I have one question.
>

Who should I CC then? I saw that you have commits in that file.

> I am wondering why this change implies better performance.
>
> Is this because when we later want to encode a new line/column, and
> hit the spot below, (in linemap_line_start via
> linemap_position_for_column), we call less linemap_add (and thus
> allocate less maps):

Almost. To be exact we don't even enter linemap_line_start() because of 
the check in linemap_position_for_column(). As a result we avoid 
almost 450K calls to linemap_line_start() (and many calls to malloc() 
subsequently), for my example case of compiling reload.c. Here is the 
source annotated by callgrind:


Before:

         .  source_location
         .  linemap_position_for_column (struct line_maps *set, unsigned int to_column)
5,193,344  {
   649,168    source_location r = set->highest_line;
         .
3,895,008    linemap_assert
         .      (!linemap_macro_expansion_map_p (LINEMAPS_LAST_ORDINARY_MAP (set)));
         .
1,298,336    if (to_column >= set->max_column_hint)
         .      {
1,696,684        if (r >= 0xC000000 || to_column > 100000)
         .  	{
         .  	  /* Running low on source_locations - disable column numbers.  */
         .  	  return r;
         .  	}
         .        else
         .  	{
         .  	  struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (set);
5,938,394  	  r = linemap_line_start (set, SOURCE_LINE (map, r), to_column + 50);
36,425,117  => line-map.c:linemap_line_start (424171x)
         .  	}
         .      }
   649,168    r = r + to_column;
1,298,336    if (r >= set->highest_location)
   640,785      set->highest_location = r;
         .    return r;
3,895,008  }



After

         .  source_location
         .  linemap_position_for_column (struct line_maps *set, unsigned int to_column)
5,193,344  {
   649,168    source_location r = set->highest_line;
         .
3,895,008    linemap_assert
         .      (!linemap_macro_expansion_map_p (LINEMAPS_LAST_ORDINARY_MAP (set)));
         .
1,298,336    if (to_column >= set->max_column_hint)
         .      {
        48        if (r >= 0xC000000 || to_column > 100000)
         .  	{
         .  	  /* Running low on source_locations - disable column numbers.  */
         .  	  return r;
         .  	}
         .        else
         .  	{
         .  	  struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (set);
       168  	  r = linemap_line_start (set, SOURCE_LINE (map, r), to_column + 50);
     2,573  => line-map.c:linemap_line_start (12x)
         .  	}
         .      }
   649,168    r = r + to_column;
1,298,336    if (r >= set->highest_location)
   640,805      set->highest_location = r;
         .    return r;
3,895,008  }



Dimitris



More information about the Gcc-patches mailing list