public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: (C++) High memory usage with templates
@ 1998-12-01 23:27 Chris Butler
  0 siblings, 0 replies; 16+ messages in thread
From: Chris Butler @ 1998-12-01 23:27 UTC (permalink / raw)
  To: Klaus-Georg Adams; +Cc: egcs

Hi, 

> > Is this normal? Is there any way I can reduce this memory usage?
> 
> So yes, this is normal. And the way to reduce this seems to be to fund
> Mark Mitchell to reduce it :-) He has improved the memory usage by some
> 10-20% in the last weeks.

I was just making sure it is normal, and not some kind of memory leak or
something. I can live with it for now, but I look forward to seeing the
changes :)

Chris


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (C++) High memory usage with templates
  1998-12-03 15:16         ` Jeffrey A Law
@ 1998-12-03 19:02           ` joel
  0 siblings, 0 replies; 16+ messages in thread
From: joel @ 1998-12-03 19:02 UTC (permalink / raw)
  To: law; +Cc: Steinar Bang, egcs

On Thu, 3 Dec 1998, Jeffrey A Law wrote:

> 
>   In message < Pine.LNX.3.96.981203072754.204E-100000@oar3remote.oarcorp.com >you
>  write:
>   > I don't know if it is relevant but there are a couple of files in the
>   > powerpc simulator included with gdb that are (AFAIK) plain C that take an
>   > enormous amount of resources to compile.  I have seen a Linux box with 256
>   > Mbytes RAM thrash trying to compile this file with optimization on.  This
>   > occurs when you configure psim to --enable-sim-inline.  Perhaps this
>   > indicates a problem that is not entirely C++ specific.  Someone more
>   > knowledgeable about psim and gcc can tell me if I am way off base here.
> When a function is declared inlined, the entire internal representation for the
> function is saved for integration into callers.
> 
> When -finline-functions is in effect (including -O3), then *every* function's
> internal representation is saved.  That alone costs a lot of memory.
> 
> When integration occurs, the resulting code is also much larger, with many more
> expressions/registers/insns.  This in turn causes a significant increase in the
> amount of memory to compile a particular function.  Particularly since some
> of the data structuers are 2X based on insns, regs or whatever.  And gcc tries
> just as hard to optimize big functions as little ones...  So it does not say
> "gee, this is a big function, maybe I shouldn't do optimization xyz..."
> 
> I looked at one case not long ago where the tables & bitmaps to implement
> global cse alone were 200+ meg for a heavily inlined/templated hunk of code.

This sounds like exactly what happens with psim.  The routine in question
(if I recall correctly) is the instruction decoder.  So when all the
instruction functionality is inlined, it gets quite large.  I suppose
there is little that can be done about it but it does show that this type
of problem is not specific to C++



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (C++) High memory usage with templates
  1998-12-03  6:09       ` joel
@ 1998-12-03 15:16         ` Jeffrey A Law
  1998-12-03 19:02           ` joel
  0 siblings, 1 reply; 16+ messages in thread
From: Jeffrey A Law @ 1998-12-03 15:16 UTC (permalink / raw)
  To: joel; +Cc: Steinar Bang, egcs

  In message < Pine.LNX.3.96.981203072754.204E-100000@oar3remote.oarcorp.com >you
 write:
  > I don't know if it is relevant but there are a couple of files in the
  > powerpc simulator included with gdb that are (AFAIK) plain C that take an
  > enormous amount of resources to compile.  I have seen a Linux box with 256
  > Mbytes RAM thrash trying to compile this file with optimization on.  This
  > occurs when you configure psim to --enable-sim-inline.  Perhaps this
  > indicates a problem that is not entirely C++ specific.  Someone more
  > knowledgeable about psim and gcc can tell me if I am way off base here.
When a function is declared inlined, the entire internal representation for the
function is saved for integration into callers.

When -finline-functions is in effect (including -O3), then *every* function's
internal representation is saved.  That alone costs a lot of memory.

When integration occurs, the resulting code is also much larger, with many more
expressions/registers/insns.  This in turn causes a significant increase in the
amount of memory to compile a particular function.  Particularly since some
of the data structuers are 2X based on insns, regs or whatever.  And gcc tries
just as hard to optimize big functions as little ones...  So it does not say
"gee, this is a big function, maybe I shouldn't do optimization xyz..."

I looked at one case not long ago where the tables & bitmaps to implement
global cse alone were 200+ meg for a heavily inlined/templated hunk of code.

jeff

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (C++) High memory usage with templates
  1998-12-02  2:52     ` Steinar Bang
  1998-12-02 18:34       ` Alexandre Oliva
@ 1998-12-03  6:09       ` joel
  1998-12-03 15:16         ` Jeffrey A Law
  1 sibling, 1 reply; 16+ messages in thread
From: joel @ 1998-12-03  6:09 UTC (permalink / raw)
  To: Steinar Bang; +Cc: egcs

On 2 Dec 1998, Steinar Bang wrote:

> >>>>> Joe Buck <jbuck@Synopsys.COM>:
> 
> >> Will these changes affect linking speed when creating laaarge
> >> shared libs?  That's where my bottleneck currently is.  This takes
> >> up to one minute for creating a 15MB .so on my PII300 (w/128MB of
> >> RAM).

I don't know if it is relevant but there are a couple of files in the
powerpc simulator included with gdb that are (AFAIK) plain C that take an
enormous amount of resources to compile.  I have seen a Linux box with 256
Mbytes RAM thrash trying to compile this file with optimization on.  This
occurs when you configure psim to --enable-sim-inline.  Perhaps this
indicates a problem that is not entirely C++ specific.  Someone more
knowledgeable about psim and gcc can tell me if I am way off base here.

--joel
Joel Sherrill                    Director of Research & Development
joel@OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (C++) High memory usage with templates
  1998-12-02  2:52     ` Steinar Bang
@ 1998-12-02 18:34       ` Alexandre Oliva
  1998-12-03  6:09       ` joel
  1 sibling, 0 replies; 16+ messages in thread
From: Alexandre Oliva @ 1998-12-02 18:34 UTC (permalink / raw)
  To: Steinar Bang; +Cc: egcs

On Dec  2, 1998, Steinar Bang <sb@metis.no> wrote:

> -fsquangle 

> Hm... this wil create yet another incompatible binary C++ format for
> .so files compiled with gcc derivates.  Not sure that is a good thing
> (which is presumably why this option is turned on by default?).

ASsuming you mean it is turned *off* by default, yes, it will lead to
binary incompatibility, but so will complete namespace support
(::std:: != ::) and the empty base class optimization, so we're
waiting for all this work to be complete before enabling all the
incompatibilities at once.

-- 
Alexandre Oliva  http://www.dcc.unicamp.br/~oliva  aoliva@{acm.org}
oliva@{dcc.unicamp.br,gnu.org,egcs.cygnus.com,samba.org}
Universidade Estadual de Campinas, SP, Brasil


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (C++) High memory usage with templates
  1998-12-02  4:40     ` Jamie Lokier
@ 1998-12-02 14:54       ` Steinar Bang
  0 siblings, 0 replies; 16+ messages in thread
From: Steinar Bang @ 1998-12-02 14:54 UTC (permalink / raw)
  To: egcs

>>>>> Jamie Lokier <egcs@tantalophile.demon.co.uk>:

> On Tue, Dec 01, 1998 at 05:45:41PM -0800, Joe Buck wrote:
>> Linking speed is a separate problem.  I suspect that -fsquangle will
>> speed up linking of large programs, because it substantially reduces
>> the size of symbols, and the linker has to page all of the symbols into
>> memory.  (You'd have to use -fsquangle to build your library as well).

> I expect using references to debugging info in other files instead of
> copying it would yield a much better improvement in link times.

Yup.  Agreed.

In comparison to the minute or so egcs uses to create the shared lib
on a PII300, Sunpro uses 13s on an UltraSPARC One busy with other
tasks.

Sunpro by default stores debug info outside of the .o files AFAIK.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (C++) High memory usage with templates
  1998-12-01 17:59   ` Joe Buck
  1998-12-02  2:52     ` Steinar Bang
@ 1998-12-02  4:40     ` Jamie Lokier
  1998-12-02 14:54       ` Steinar Bang
  1 sibling, 1 reply; 16+ messages in thread
From: Jamie Lokier @ 1998-12-02  4:40 UTC (permalink / raw)
  To: Joe Buck, Steinar Bang; +Cc: egcs

On Tue, Dec 01, 1998 at 05:45:41PM -0800, Joe Buck wrote:
> Linking speed is a separate problem.  I suspect that -fsquangle will
> speed up linking of large programs, because it substantially reduces
> the size of symbols, and the linker has to page all of the symbols into
> memory.  (You'd have to use -fsquangle to build your library as well).

I expect using references to debugging info in other files instead of
copying it would yield a much better improvement in link times.

-- Jamie

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (C++) High memory usage with templates
  1998-12-01 17:59   ` Joe Buck
@ 1998-12-02  2:52     ` Steinar Bang
  1998-12-02 18:34       ` Alexandre Oliva
  1998-12-03  6:09       ` joel
  1998-12-02  4:40     ` Jamie Lokier
  1 sibling, 2 replies; 16+ messages in thread
From: Steinar Bang @ 1998-12-02  2:52 UTC (permalink / raw)
  To: egcs

>>>>> Joe Buck <jbuck@Synopsys.COM>:

>> Will these changes affect linking speed when creating laaarge
>> shared libs?  That's where my bottleneck currently is.  This takes
>> up to one minute for creating a 15MB .so on my PII300 (w/128MB of
>> RAM).

> Linking speed is a separate problem.  I suspect that -fsquangle will
> speed up linking of large programs, because it substantially reduces
> the size of symbols, and the linker has to page all of the symbols
> into memory.  (You'd have to use -fsquangle to build your library as
> well).

Hm... what does -fsquangle do?  I couldn't find a description of it in 
the info pages... ah... Alta Vista's your friend...:

-fsquangle 
-fno-squangle 
	-fsquangle will enable a compressed form of name mangling for
	identifiers. In particular, it helps to shorten very long
	names by recognizing types and class names which occur more
	than once, replacing them with special short ID codes. This
	option also requires any C++ libraries being used to be
	compiled with this option as well. The compiler has this
	disabled (the equivalent of -fno-squangle) by default.

Hm... this wil create yet another incompatible binary C++ format for
.so files compiled with gcc derivates.  Not sure that is a good thing
(which is presumably why this option is turned on by default?).

Of course, I *could* put this into my debug build setup (where the
size is a problem in the first place) and build relases using the
normal name mangling scheme.  But I still would have a problem with
3rd party libraries where I don't have the option of recompiling
them. 

But thanx for the tip!


- Steinar

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (C++) High memory usage with templates
  1998-12-01  8:19 ` Steinar Bang
@ 1998-12-01 17:59   ` Joe Buck
  1998-12-02  2:52     ` Steinar Bang
  1998-12-02  4:40     ` Jamie Lokier
  0 siblings, 2 replies; 16+ messages in thread
From: Joe Buck @ 1998-12-01 17:59 UTC (permalink / raw)
  To: Steinar Bang; +Cc: egcs

> >> Is this normal? Is there any way I can reduce this memory usage?
> 
> > So yes, this is normal. And the way to reduce this seems to be to
> > fund Mark Mitchell to reduce it :-) He has improved the memory usage
> > by some 10-20% in the last weeks.
> 
> Will these changes affect linking speed when creating laaarge shared
> libs?  That's where my bottleneck currently is.  This takes up to one
> minute for creating a 15MB .so on my PII300 (w/128MB of RAM).

Linking speed is a separate problem.  I suspect that -fsquangle will
speed up linking of large programs, because it substantially reduces
the size of symbols, and the linker has to page all of the symbols into
memory.  (You'd have to use -fsquangle to build your library as well).


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (C++) High memory usage with templates
  1998-11-30  2:27 Klaus-Georg Adams
  1998-11-30 23:25 ` Joe Buck
@ 1998-12-01  8:19 ` Steinar Bang
  1998-12-01 17:59   ` Joe Buck
  1 sibling, 1 reply; 16+ messages in thread
From: Steinar Bang @ 1998-12-01  8:19 UTC (permalink / raw)
  To: egcs

>>>>> Klaus-Georg Adams <Klaus-Georg.Adams@chemie.uni-karlsruhe.de>:

> Chris wrote:

>> Is this normal? Is there any way I can reduce this memory usage?

> So yes, this is normal. And the way to reduce this seems to be to
> fund Mark Mitchell to reduce it :-) He has improved the memory usage
> by some 10-20% in the last weeks.

Will these changes affect linking speed when creating laaarge shared
libs?  That's where my bottleneck currently is.  This takes up to one
minute for creating a 15MB .so on my PII300 (w/128MB of RAM).

Memory usage goes right up, and CPU usage is only 29%, so I suspect
that much of the time is spent waiting for existing pages to page
out... 

Oh well!

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (C++) High memory usage with templates
  1998-11-30 23:25 ` Joe Buck
@ 1998-12-01  1:10   ` Klaus-Georg Adams
  0 siblings, 0 replies; 16+ messages in thread
From: Klaus-Georg Adams @ 1998-12-01  1:10 UTC (permalink / raw)
  To: jbuck; +Cc: chrisb, egcs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1509 bytes --]

>>>>> "Joe" == Joe Buck <jbuck@synopsys.com> writes:

    >> You haven't seen anything yet: when I try to compile examples
    >> from the blitz library ( http://monet.uwaterloo.ca/blitz/ ) I see
    >> memory usages of about 400M from cc1plus.

    Joe> Which C++ version are you using?  Early egcs versions as well
    Joe> as g++2.8.1 are particularly greedy for complex templates,
    Joe> but later versions are better.

Compiling blitz-19980903/testsuite/storage.cpp with
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
I see:

g++ -I./.. -ftemplate-depth-30 -O2 -funroll-loops -fstrict-aliasing -g -DBZ_DEBUG -g -DBZ_DEBUG  -c ./storage.cpp
g++: Internal compiler error: program cc1plus got fatal signal 11
 
and a peak memory usage as reported by top of 305M.

With 
reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.92.25/specs
gcc version egcs-2.92.25 19981130 (gcc2 ss-980609 experimental)
the result is the same (signal 11), but the memory usage is down
to 299M.

I haven't verified other files of the blitz library now, but I
remember having seen 400M.

-- kga
-------------------------------------------------------------------------
Klaus-Georg Adams        Email: Klaus-Georg.Adams@chemie.uni-karlsruhe.de
Institut f. Anorg. Chemie, Lehrstuhl II            Tel: 49(0)721 608 3485
Universität Karlsruhe, D-76128 Karlsruhe
-------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (C++) High memory usage with templates
  1998-11-30  2:27 Klaus-Georg Adams
@ 1998-11-30 23:25 ` Joe Buck
  1998-12-01  1:10   ` Klaus-Georg Adams
  1998-12-01  8:19 ` Steinar Bang
  1 sibling, 1 reply; 16+ messages in thread
From: Joe Buck @ 1998-11-30 23:25 UTC (permalink / raw)
  To: Klaus-Georg Adams; +Cc: chrisb, egcs

> You haven't seen anything yet: when I try to compile examples from the
> blitz library ( http://monet.uwaterloo.ca/blitz/ ) I see memory usages
> of about 400M from cc1plus.

Which C++ version are you using?  Early egcs versions as well as g++2.8.1
are particularly greedy for complex templates, but later versions are
better.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (C++) High memory usage with templates
  1998-11-29 13:30 Chris Butler
@ 1998-11-30 23:25 ` Martin von Loewis
  0 siblings, 0 replies; 16+ messages in thread
From: Martin von Loewis @ 1998-11-30 23:25 UTC (permalink / raw)
  To: chrisb; +Cc: egcs

> Is this normal? Is there any way I can reduce this memory usage?

You didn't mention the compiler version, but yes, this is normal for
most releases. I recommend to update to the current development
snapshots, which might offer some improvements. Also, as recent
investigations show, squangling may offer improvements.

Regards,
Martin

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (C++) High memory usage with templates
@ 1998-11-30  2:27 Klaus-Georg Adams
  1998-11-30 23:25 ` Joe Buck
  1998-12-01  8:19 ` Steinar Bang
  0 siblings, 2 replies; 16+ messages in thread
From: Klaus-Georg Adams @ 1998-11-30  2:27 UTC (permalink / raw)
  To: chrisb; +Cc: egcs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1002 bytes --]

Chris wrote:

> When compiling programs that make heavy use of templates (mainly the
> STL), I often see cc1plus wanting about 15 megs of RAM. On my 24 meg
> machine this is major performance hit. (I've not dared try it on my
> 10 meg machine!)

You haven't seen anything yet: when I try to compile examples from the
blitz library ( http://monet.uwaterloo.ca/blitz/ ) I see memory usages
of about 400M from cc1plus.

> Is this normal? Is there any way I can reduce this memory usage?

So yes, this is normal. And the way to reduce this seems to be to fund
Mark Mitchell to reduce it :-) He has improved the memory usage by some
10-20% in the last weeks.

-- kga
-------------------------------------------------------------------------
Klaus-Georg Adams        Email: Klaus-Georg.Adams@chemie.uni-karlsruhe.de
Institut f. Anorg. Chemie, Lehrstuhl II            Tel: 49(0)721 608 3485
Universität Karlsruhe, D-76128 Karlsruhe
-------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 16+ messages in thread

* (C++) High memory usage with templates
@ 1998-11-29 13:30 Chris Butler
  0 siblings, 0 replies; 16+ messages in thread
From: Chris Butler @ 1998-11-29 13:30 UTC (permalink / raw)
  To: egcs

Hi,

In addition to my previous message, here is a short program that
demonstrates this behaviour.

== start memory-test.cc ==
//
// Demonstrate the high memory usage when compiling with templates
//
// With -O2 turned on, cc1plus uses about 10megs compiling
// this. Without optimisation, it uses about 6megs.

#include <vector>
#include <map>
#include <string>

int main()
{
	typedef map<string, unsigned short> myMap;
	typedef vector<myMap> someMaps;

	myMap fred, barney;
	someMaps wilma;

	fred.insert(pair<string, unsigned short>("foo", 1));
	fred.insert(pair<string, unsigned short>("bar", 2));

	barney.insert(pair<string, unsigned short>("foo", 2));
	barney.insert(pair<string, unsigned short>("bar", 1));

	wilma.push_back(fred);
	wilma.push_back(barney);
}
== end memory-test.cc ==

--
Chris Butler
<chrisb@sandy.force9.co.uk>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* (C++) High memory usage with templates
@ 1998-11-29 13:30 Chris Butler
  1998-11-30 23:25 ` Martin von Loewis
  0 siblings, 1 reply; 16+ messages in thread
From: Chris Butler @ 1998-11-29 13:30 UTC (permalink / raw)
  To: egcs

Hi,

When compiling programs that make heavy use of templates (mainly the
STL), I often see cc1plus wanting about 15 megs of RAM. On my 24 meg
machine this is major performance hit. (I've not dared try it on my 10
meg machine!)

Is this normal? Is there any way I can reduce this memory usage?

Chris
<chrisb@sandy.force9.co.uk>

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~1998-12-03 19:02 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-01 23:27 (C++) High memory usage with templates Chris Butler
  -- strict thread matches above, loose matches on Subject: below --
1998-11-30  2:27 Klaus-Georg Adams
1998-11-30 23:25 ` Joe Buck
1998-12-01  1:10   ` Klaus-Georg Adams
1998-12-01  8:19 ` Steinar Bang
1998-12-01 17:59   ` Joe Buck
1998-12-02  2:52     ` Steinar Bang
1998-12-02 18:34       ` Alexandre Oliva
1998-12-03  6:09       ` joel
1998-12-03 15:16         ` Jeffrey A Law
1998-12-03 19:02           ` joel
1998-12-02  4:40     ` Jamie Lokier
1998-12-02 14:54       ` Steinar Bang
1998-11-29 13:30 Chris Butler
1998-11-29 13:30 Chris Butler
1998-11-30 23:25 ` Martin von Loewis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).