LWN.net Logo

What's new in GCC 4.5?

What's new in GCC 4.5?

Posted May 20, 2010 3:56 UTC (Thu) by quotemstr (subscriber, #45331)
In reply to: What's new in GCC 4.5? by roelofs
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.)


(Log in to post comments)

What's new in GCC 4.5?

Posted May 20, 2010 10:03 UTC (Thu) by jwakely (subscriber, #60262) [Link]

See http://www.cs.huji.ac.il/~dants/papers/MinimizeDependenci... for another technique for reducing template instantiations without having to resort to function pointers.

What's new in GCC 4.5?

Posted May 30, 2010 1:01 UTC (Sun) by roelofs (guest, #2599) [Link]

Was that with or without debugging symbols?

With. In this application, auto-gdb-backtrace was pretty much a necessity.

I'm no longer working on that particular project (or even in C++), but I'll keep jwakely's and your suggestions handy in case it crops up again.

Thanks,
Greg

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds