[gnu.g++.bug] Just thought you'd like to know

schmidt@zola.ics.uci.edu (Doug Schmidt) (09/10/89)

In article <8909092016.AA05850@teacake.sun.com>, tiemann@SUN (Michael Tiemann) writes:
>Without -fsave-memoized:
>    35131 fields searched in 4557[17093] calls to lookup_field[_1]
>    226706 fnfields searched in 6051 calls to lookup_fnfields
>    4740 calls to get_base_type
>    Data size 3596288.
>
>With -fsave-memoized:
>    780 memoized contexts saved
>    410 local tree nodes made
>    28 local hash nodes made
>    fields statistics:
>      memoized finds = 161; rejects = 4305; (searches = 467)
>      memoized_adds = 75
>    fnfields statistics:
>      memoized finds = 329; rejects = 137; (searches = 6396)
>      memoized_adds = 79
>    420 fields searched in 91[192] calls to lookup_field[_1]
>    5319 fnfields searched in 98 calls to lookup_fnfields
>    4043 calls to get_base_type
>    Data size 2764800.

People interested in a description of the erstwhile mysterious options
-fsave-memoized and -fmemoize-lookups should find the following 
documentation useful (taken from latest g++.texinfo):

----------------------------------------
@item -fsave-memoized
@item -fmemoize-lookups
These flags are of use to get the compiler to compile programs faster
using heuristics.  They are not on by default since they only do so
about half the time.  They other half of the time programs compile more
slowly (and take more memory).

The first time the compiler must build a call to a member function (or
reference to a data member), it must (1) determine whether the class
implements member functions of that name (2) resolve which member
function to call (which involves figuring out what sorts of type
conversions need to be made), and (3) check the visibility of the member
function to the caller.  All of this adds up to slower compilation.
Normally, the second time a call is made to that member function (or
reference to that data member), it must go through the same lengthy
process again.  This means that code like this

@example
  cout << "This " << p << " has " << n << " legs.\n";
@end example

@noindent
makes six passes through all three steps.  By using a software cache,
a ``hit'' significantly reduces this cost.  Unfortunately, using the
cache introduces another layer of mechanisms which must be implemented,
and so incurrs its own overhead.  The @samp{-fmemoize-lookups} enables
the software cache.

Because access privileges (visibility) to members and member functions
may differ from one function context to the next, may need to be
flushed.  With the @samp{-fmemoize-lookups} flag, the cache is flushed
after every function that is compiled.  With the @samp{-fsave-memoized} 
flag, when the compiler determines that the context of the last function
compiled would yield the same access privileges of the next function to
compile, it preserves the cache.  This really helps when defining many
member functions for the same class: with the exception of member
functions which are friends of other classes, each member function has
exactly the same access privileges as every other, and the cache need
not be flushed.
----------------------------------------

Doug
--
schmidt@ics.uci.edu (ARPA) |   Per me si va nella citta' dolente.
office: (714) 856-4043     |   Per me si va nell'eterno dolore.
                           |   Per me si va tra la perduta gente.
                           |   Lasciate ogni speranza o voi ch'entrate.