Overhead of DIP1036
Timon Gehr
timon.gehr at gmx.ch
Tue Jan 9 22:38:17 UTC 2024
On 1/9/24 20:05, Walter Bright wrote:
> On 1/9/2024 12:45 AM, Alexandru Ermicioi wrote:
>> If that's the case, then 1036 wins imho, by simple thing of not doing
>> any parsing of format string.
>
> Consider the overhead 1036 has by comparing it with plain writeln or
> writefln:
>
> ```
> void test(int baz)
> {
> writeln(i"$(baz + 4)");
> writeln(baz + 5);
> writefln("%d", baz + 6);
> }
> ```
>
> ...
I think Alexandru and Nickolay already discharged the concerns about
overhead pretty well, but just note that with DIP1027, `test(3)` prints:
%s7
8
9
There is fundamentally no way to make this work correctly, due to how
DIP1027 throws away the information about the format string.
With DIP1036e, `test(3)` prints:
7
8
9
And you can get rid of the runtime overhead by adding a `pragma(inline,
true)` `writeln` overload. (I guess with DMD that will still bloat the
executable, but I think other compiler backends and linkers can be made
elide such symbols completely.)
More information about the Digitalmars-d
mailing list