boost::function code size

Hello, I've became interested in how efficient code-size-wise boost::function is, so I wrote a small script which generates a function which calls boost::function object N times and finds the size of the generated function. The results are somewhat interesting and somewhat alarming (to me). On gcc 3.3 with -Os, each call to boost::function costs 147 bytes of code size. With -O3 it's about 166 bytes. On gcc 3.4 calls cost 203 bytes with -Os and between 220 and 240 with -O3. However, when boost::function is called 15 times, the inliner heuristics kick in and calls are no longer inlined -- meaning each call costs about 14 bytes. This is a good thing for 3.4, but still: 1. For 3.3 boost::function causes a serious code bloat. 2. Even for 3.4, I'm not sure how it will perform if calls are done in several modules. Or how the heuristics will work on non-trivial cases: if they use the % of size increase then on large modules boost::function inlining can cost much more. Given that, IIUC, boost::function has to do indirect call somewhere anyway, I'm not sure inlining is such a good idea. Maybe some of the methods should be declared out-of-line, so that compiler don't try to inline them? - Volodya

On Wednesday 30 June 2004 4:44 am, Vladimir Prus wrote:
Hello, I've became interested in how efficient code-size-wise boost::function is, so I wrote a small script which generates a function which calls boost::function object N times and finds the size of the generated function.
The results are somewhat interesting and somewhat alarming (to me). [snip] Given that, IIUC, boost::function has to do indirect call somewhere anyway, I'm not sure inlining is such a good idea. Maybe some of the methods should be declared out-of-line, so that compiler don't try to inline them?
If I can find a way to do it that won't break many compilers (e,g,, MSVC 6 that can't handle out-of-line definitions for templates) I'll do this for 1.32.0; otherwise, it'll have to wait until after the release. Doug

Doug Gregor wrote:
Given that, IIUC, boost::function has to do indirect call somewhere anyway, I'm not sure inlining is such a good idea. Maybe some of the methods should be declared out-of-line, so that compiler don't try to inline them?
If I can find a way to do it that won't break many compilers (e,g,, MSVC 6 that can't handle out-of-line definitions for templates) I'll do this for 1.32.0; otherwise, it'll have to wait until after the release.
Maybe, we can #ifdef MSVC6 and use inline definition on that comlier? I've tried the attached patch and each call now costs about 20bytes (even 14 on 3.4), which is quite an improvement. - Volodya

On Jul 2, 2004, at 3:25 AM, Vladimir Prus wrote:
Doug Gregor wrote:
Given that, IIUC, boost::function has to do indirect call somewhere anyway, I'm not sure inlining is such a good idea. Maybe some of the methods should be declared out-of-line, so that compiler don't try to inline them?
If I can find a way to do it that won't break many compilers (e,g,, MSVC 6 that can't handle out-of-line definitions for templates) I'll do this for 1.32.0; otherwise, it'll have to wait until after the release.
Maybe, we can #ifdef MSVC6 and use inline definition on that comlier? I've tried the attached patch and each call now costs about 20bytes (even 14 on 3.4), which is quite an improvement.
I've checked in your patch, using BOOST_WORKAROUND instead of _MSVC. Thanks! Doug
participants (2)
-
Doug Gregor
-
Vladimir Prus