Overhead of DIP1036

Steven Schveighoffer schveiguy at gmail.com
Tue Jan 9 23:33:05 UTC 2024


On Tuesday, 9 January 2024 at 19:05:40 UTC, Walter Bright wrote:

> With the istring, there are 4 calls to struct member functions 
> that just return null.

Yeah, and writeln could avoid those if it's that important. A 
good optimizer will remove that call.

> This can't be good for performance or program size.

Then use writeln the way you want? I don't see it as significant 
at all.

> 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

I find it bizarre to be concerned about the call performance of 
zero-sized structs and empty strings to writeln or writef, like 
the function is some shining example of performance or efficient 
argument passing. If you do not have inlining or optimizations 
enabled, do you think the call tree of writefln is going to be 
compact? Not to mention it eventually just calls into C opaquely.

Note that you can write a simple wrapper that can be inlined, 
which will mitigate all of this via compile-time transformations.

If you like, I can write it up and you can try it out!

-Steve


More information about the Digitalmars-d mailing list