On 2/8/16 8:19 AM, wobbles wrote:
On Monday, 8 February 2016 at 13:01:44 UTC, Steven Schveighoffer wrote:
On 2/7/16 12:18 AM, Steven Schveighoffer wrote:
I have a library where I was using very many voldemort types a la
std.range.
[snip]
Is there a better way we should be doing this? I'm wondering if
voldemort types are really worth it. They offer a lot of convenience,
and are much DRYer than separate private template types. But the bloat
cost is not really worth the convenience IMO.
I modified all my voldemort-returning functions to return module-level
types.
One of my example programs (compiled optimized/inline) went from 10MB
to 1MB. The other example program went from 2.1MB to 900k.
Just to be sure, you replaced something like this:
auto myFunc(int x){
struct MyStruct{ int a; }
return MyStruct(x);
}
with?
private struct MyStruct{ int a; }
auto myFunc(int x){
return MyStruct(x);
}
Yes, but with template parameters. It's not so much the moving of the
struct that reduced the bloat, but the nature of how the template
parameters are used. Each function that returns one of these structs
wraps another such struct, so the template bloat is exponential because
of the repeat of the template parameter for the function argument. By
moving the struct into the module, there is only one specification of
the template parameter for the name mangling. Basically, I changed a.b.c
bloat factor from 2^3 to 1^3.
-Steve