What's new in GCC 4.5?
Posted May 20, 2010 3:56 UTC (Thu) by quotemstr
In reply to: What's new in GCC 4.5?
Parent article: What's new in GCC 4.5?
A 15 MB C-only executable grew to ~600 MB as parts of it were rewritten in C++
That's huge! There's no good reason to tolerate that level of bloat. Was that with or without debugging symbols?
Part of the cause is almost certainly forced inline function generaton. Using hidden symbols allows the compiler to skip the generaiton of certain functions --- if they're private symbols, the compiler can assume they're not overwritten at load-time.
Another thing to keep in mind is C++ template generation, as you mentioned. It's easy to achieve a combinatorial explosion of template instantiations when you have a template library used in many difficult circumstances. It's often worthwhile to have generic, templated code just be an inline-only, typesafe wrapper around concrete code; use function pointers to let that concrete code safely work with whatever the higher-level wrapper gives it.
Using that approach, you give up a tiny bit of runtime performance for a huge reduction in code size. Imagine the difference between qsort() and std::sort --- it's easy to write the latter such that the entire sorting agorithm implementation is emitted once per type sorted! (It's also possible for a C++ library implementor to write std::sort using the type erasure technique I mention.)
to post comments)