C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Small (but slower) Standard Library Implementation?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Allan Odgaard
Guest





PostPosted: Fri Feb 20, 2004 2:57 pm    Post subject: Small (but slower) Standard Library Implementation? Reply with quote



The standard library (STL) implementations which I am familiar with
all seem to concern themselve with generating the best possible code
-- e.g. unfolding std::find when handed random access iterators, using
memcpy for std::copy when the iterators are pointers etc.

This result in a lot of code which affect compile time (and also code
size, since the standard algorithms are maybe 10 lines instead of 3).
A simple program like the following, using some standard includes:

#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>

int main (int argc, char const* argv[])
{
return 0;
}

Takes 4-5 seconds to compile on my 733 MHz G4, using gcc 3.3 from
Apple (after the headers have been cached). Since these files are
probably included in most of my sources, it would seem that the
minimum compile time for any of my sources is around 5 seconds, which
is a rather high price IMHO.

Including only vector takes around a second, whereas writing my own
(partly complying) std::vector replacement takes virtually no time to
compile.

So I was curious if others have investigated this subject? and if
anyone knows of a simpler STL implementation? I would certainly favor
something simple if it means that the include overhead goes from 5
seconds to 1 pr. source.

Also, I wonder if the optimizations in the (gcc, previously SGI) STL
really matters, or actually just makes things worse. At least for many
of the things I do, I would probably be better off without the fancy
optimizations, for example I use only user types with std::copy, so I
pay for having the iterators copied 4 times, but still do not get to
an implementation more "optimized" than a standard loop, I use
std::find generally for small datasets, and so the unrolled version
just result in code bloat, and insert for std::vector also seem to be
geared toward inserting large quantities of data, at least inserting 2
elements in a std::vector 10 million times is significantly slower
than doing the same with the array provided by my operating system,
where each insertion goes through dynamic dispatch. But looking at the
code for std::vector::insert also show that there is some overhead
again trying to find the optimal way to insert the values (which,
although much resolved at compile time, is slower than the dynamic
dispatch done by the ObjC run-time that my OS uses for calling member
functions on an array object).

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Ben Hutchings
Guest





PostPosted: Sat Feb 21, 2004 4:22 am    Post subject: Re: Small (but slower) Standard Library Implementation? Reply with quote



Allan Odgaard wrote:
Quote:
The standard library (STL) implementations which I am familiar with
all seem to concern themselve with generating the best possible code
-- e.g. unfolding std::find when handed random access iterators, using
memcpy for std::copy when the iterators are pointers etc.

This result in a lot of code which affect compile time (and also code
size, since the standard algorithms are maybe 10 lines instead of 3).
A simple program like the following, using some standard includes:
snip
Takes 4-5 seconds to compile on my 733 MHz G4, using gcc 3.3 from
Apple (after the headers have been cached). Since these files are
probably included in most of my sources, it would seem that the
minimum compile time for any of my sources is around 5 seconds, which
is a rather high price IMHO.

This problem can be reduced greatly by using "pre-compiled headers".
These have been implemented in many other compilers and will be
available in GCC from version 3.4. Based on past release history
I think this will be released around the middle of this year.

<snip>
Quote:
Also, I wonder if the optimizations in the (gcc, previously SGI) STL
really matters, or actually just makes things worse. At least for many
of the things I do, I would probably be better off without the fancy
optimizations, for example I use only user types with std::copy, so I
pay for having the iterators copied 4 times, but still do not get to
an implementation more "optimized" than a standard loop,
snip


You might consider paying for a compiler that generates better code
for the PowerPC. So far as I know, GCC does not have many PowerPC-
specific optimisations. Before doing that, though, it might be worth
tweaking the optimisation settings if you haven't already done so.

GCC 3.4 is supposed to do a much better job of choosing when to
compile code inline, which might improve the machine code you get. It
also has a new C++ parser which may be faster, but I don't think
parsing accounts for that large a part of compilation t ime.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.