Overhead of DIP1036
Walter Bright
newshound2 at digitalmars.com
Tue Jan 9 19:05:40 UTC 2024
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);
}
```
Generated code:
0000: 55 push RBP
0001: 48 8B EC mov RBP,RSP
0004: 48 83 EC 20 sub RSP,020h
0008: 48 89 5D E8 mov -018h[RBP],RBX
000c: 89 7D F8 mov -8[RBP],EDI // baz
000f: 48 83 EC 08 sub RSP,8
0013: 31 C0 xor EAX,EAX
0015: 88 45 F0 mov -010h[RBP],AL
0018: 48 8D 75 F0 lea RSI,-010h[RBP]
001c: FF 36 push dword ptr [RSI] // header
001e: 88 45 F1 mov -0Fh[RBP],AL
0021: 48 8D 5D F1 lea RBX,-0Fh[RBP]
0025: FF 33 push dword ptr [RBX] //
expression!"baz + 4"
0027: 8D 7F 04 lea EDI,4[RDI] // baz + 4
002a: 88 45 F2 mov -0Eh[RBP],AL
002d: 48 8D 75 F2 lea RSI,-0Eh[RBP]
0031: FF 36 push dword ptr [RSI] // footer
0033: E8 00 00 00 00 call writeln
0038: 48 83 C4 20 add RSP,020h
003c: 8B 45 F8 mov EAX,-8[RBP]
003f: 8D 78 05 lea EDI,5[RAX] // baz + 5
0042: E8 00 00 00 00 call writeln
0047: BA 00 00 00 00 mov EDX,0 // "%d".ptr
004c: BE 02 00 00 00 mov ESI,2 // "%d".length
0051: 8B 4D F8 mov ECX,-8[RBP]
0054: 8D 79 06 lea EDI,6[RCX] // baz + 6
0057: E8 00 00 00 00 call writefln
005c: 48 8B 5D E8 mov RBX,-018h[RBP]
0060: C9 leave
0061: C3 ret
With the istring, there are 4 calls to struct member functions that just return
null.
This can't be good for performance or program size.
We can compute the number of arguments passed to the function:
istring: 1 + 3 * <number of arguments> + 1 + 1 (*)
writeln: <number of arguments>
writefln: 1 + <number of arguments>
(*) includes string literals before, between, and after arguments
More information about the Digitalmars-d
mailing list