Boost C++ Libraries: Ticket #9232: Template bloat https://svn.boost.org/trac10/ticket/9232 <p> With integers of size N powm() will instantiate divide_unsigned_helper&lt;&gt; for N and N*2, since this is a very large function this leads to classical template bloat. Examining the codegen it appears that both instantiations are nearly identical save for immediate constants -&gt; this would suggest that you could refactor divide_unsigned_helper&lt;&gt; (and probably the rest of the library) so that it separates functionality that actually depends on template parameters from template-parameter independent code into separate functions (in this case divide_unsigned_helper would probably call a helper function that takes the size of the number as a runtime parameter). </p> <p> ps. even when different function template instantiations result in identical code there are _still_ lousy compilers&amp;linkers that will not merge them (Clang we are looking at you: <a class="ext-link" href="http://llvm.org/bugs/show_bug.cgi?id=11633"><span class="icon">​</span>http://llvm.org/bugs/show_bug.cgi?id=11633</a>)... </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9232 Trac 1.4.3 John Maddock Sat, 12 Oct 2013 10:07:21 GMT <link>https://svn.boost.org/trac10/ticket/9232#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9232#comment:1</guid> <description> <p> That's not so easy: divide_unsigned_helper calls a lot of other functions (add/subtract etc) which depend on the template parameters. So I don't believe the code is as close to identical as you think. I'll have to think this one over. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Domagoj Šarić</dc:creator> <pubDate>Sat, 12 Oct 2013 12:00:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9232#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9232#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/9232#comment:1" title="Comment 1">johnmaddock</a>: </p> <blockquote class="citation"> <p> That's not so easy: divide_unsigned_helper calls a lot of other functions (add/subtract etc) which depend on the template parameters. So I don't believe the code is as close to identical as you think. </p> </blockquote> <p> As I said look at the codegen (in x64 builds the functions are even identical in size, for x86 they differ in a few bytes)...maybe the abstractions are "blinding you from the Truth" XD </p> <p> ps. you might find other parts of your code that could do with a similar rework (this is unfortunately a standard 'plague' of many a 'modern C++ programer', 'top of the pops' Boost ones included)... </p> </description> <category>Ticket</category> </item> </channel> </rss>