digitalmars.D - D2.x writef et al and template bloat
- Bill Baxter (7/7) Oct 16 2007 It seems like writef and many other functions got changed to vararg
- Walter Bright (8/14) Oct 16 2007 Yes. That makes them run much faster. Instead of interpreting the format...
- BCS (3/24) Oct 16 2007 If you want to known how many cases there are you can add a pragma(msg, ...
It seems like writef and many other functions got changed to vararg templates in D2.x. Doesn't this mean there will be a different instantiation of the writef template for every combination of arguments used to call it? Sounds like it could lead to a lot of template bloat in D executables. Is it a non-issue for some reason? --bb
Oct 16 2007
Bill Baxter wrote:It seems like writef and many other functions got changed to vararg templates in D2.x.Yes. That makes them run much faster. Instead of interpreting the format at runtime, each format gets custom code.Doesn't this mean there will be a different instantiation of the writef template for every combination of arguments used to call it?Yes - but I'll correct that for every *type* combination of arguments.Sounds like it could lead to a lot of template bloat in D executables. Is it a non-issue for some reason?The linker will remove duplicates. However, I think even in a large program, there won't be that many combinations. It also has the potential to *reduce* code bloat in small programs, as the unused formatting code won't be there.
Oct 16 2007
Reply to Walter,Bill Baxter wrote:If you want to known how many cases there are you can add a pragma(msg, formatTypeTupleTemplateWidgit!(args)) to wrightf and then filter the output for unique lines.It seems like writef and many other functions got changed to vararg templates in D2.x.Yes. That makes them run much faster. Instead of interpreting the format at runtime, each format gets custom code.Doesn't this mean there will be a different instantiation of the writef template for every combination of arguments used to call it?Yes - but I'll correct that for every *type* combination of arguments.Sounds like it could lead to a lot of template bloat in D executables. Is it a non-issue for some reason?The linker will remove duplicates. However, I think even in a large program, there won't be that many combinations. It also has the potential to *reduce* code bloat in small programs, as the unused formatting code won't be there.
Oct 16 2007