 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Sarir Khamsi Guest
|
Posted: Tue Jan 20, 2004 11:26 am Post subject: Template taking a _long_ time to compile |
|
|
I'm working on a data store to hold any type of object. It is based
slightly on boost::any, but I found that class to be too cumbersome to
use. Briefly, the more elements I add to the store, it appears to
increase the compile time quadratically.
The data store class looks like:
class Store {
public:
typedef std::map<const char *, Any*> Data;
// members
private:
Data data_; // this is where all the data is
};
The class Any looks like:
class Any {
public:
template<typename T>
Any(const T &value) :
pHeld_(new Holder<T>(value)) { }
private:
HolderBase *pHeld_;
};
(HolderBase is not a class template.) The class Holder looks like:
template<typename T>
class Holder : public HolderBase
{
public:
Holder(const T &value) :
HolderBase(),
value_(value) { }
// yes, it's public
typename Types<T>::value_type value_;
};
Types is a type generator:
template<typename T> struct Types { typedef T value_type; };
When I try and add more elements to the map data_ member in Store's ctor
with:
Store::Store() :
data_()
{
data_["vel"] = new Any(double(5.9));
data_["mode"] = new Any(int(73));
data_["finishedBIT"] = new Any(bool(false));
// add more elements here
}
I'm fine until I get to larger numbers of elements. It seems like the
more elements I add, the longer it takes to compile...a lot
longer...not what I would have expected. This is using gcc 3.3.1 on
Win2k, SP3.
My questions are:
1) Is there a way to find out where the compiler spending most of its
time?
2) I tried to explicitly instantiate some templates, such as
template Any::Any(const int&);
template Any::Any(const unsigned int&);
template Any::Any(const double&);
but that didn't help. Is there something else I can do as far as
explicit instantiation is concerned to speed up the compile?
3) What's wrong with this code?
4) Is my code possessed by some satanic entity?
Thanks.
Sarir
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
David Abrahams Guest
|
Posted: Wed Jan 21, 2004 9:18 am Post subject: Re: Template taking a _long_ time to compile |
|
|
Sarir Khamsi <sarir_a_khamsi (AT) raytheon (DOT) com> writes:
| Quote: | My questions are:
1) Is there a way to find out where the compiler spending most of its
time?
|
Rebuild from source and profile the compiler.
| Quote: | 2) I tried to explicitly instantiate some templates, such as
template Any::Any(const int&);
template Any::Any(const unsigned int&);
template Any::Any(const double&);
but that didn't help. Is there something else I can do as far as
explicit instantiation is concerned to speed up the compile?
|
Doubtful.
| Quote: | 3) What's wrong with this code?
|
Nothing.
| Quote: | 4) Is my code possessed by some satanic entity?
|
Nope. As a rule, compiler implementations are very stupid about
template instantiation. Most implementations seem to stick all the
instantiations of a given template in a single long linked list, which
can easily lead to O(N^2) compile times. Some have much, much lower
constant factors than others, though. Metrowerks is by far the
fastest we've tested. GCC seems to exhibit the least-explainable
performance results of all of them. It's really, really slow in many
cases, but in some tests where it ought to get slower as the problem
size increases, it actually speeds up slightly.
Are you sticking a lot more types in your Any object, or is it
limited to just a handful?
I suggest submitting a bug report to the GCC developers
([url]http://gcc.gnu.org/bugzilla/)[/url].
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Sarir Khamsi Guest
|
Posted: Wed Jan 28, 2004 2:29 pm Post subject: Re: Template taking a _long_ time to compile |
|
|
David Abrahams <dave (AT) boost-consulting (DOT) com> writes:
| Quote: | Nope. As a rule, compiler implementations are very stupid about
template instantiation. Most implementations seem to stick all the
instantiations of a given template in a single long linked list, which
can easily lead to O(N^2) compile times. Some have much, much lower
constant factors than others, though. Metrowerks is by far the
fastest we've tested. GCC seems to exhibit the least-explainable
performance results of all of them. It's really, really slow in many
cases, but in some tests where it ought to get slower as the problem
size increases, it actually speeds up slightly.
|
Well that might explain some things. Sounds like trying a new compiler
is in order to verify this claim.
| Quote: | Are you sticking a lot more types in your Any object, or is it
limited to just a handful?
|
There are many insertions into the std::map, but most of them are
built-in types (typedef'ed, though). There are some structs in there
but are in the minority.
| Quote: | I suggest submitting a bug report to the GCC developers
([url]http://gcc.gnu.org/bugzilla/)[/url].
|
Thanks, that's another option I can try.
Sarir
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
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
|
|