[Issue 24523] writeln doesn't memoize its templates

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Apr 27 01:24:03 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24523

Steven Schveighoffer <schveiguy at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |schveiguy at gmail.com
         Resolution|---                         |WONTFIX
           Severity|normal                      |enhancement

--- Comment #1 from Steven Schveighoffer <schveiguy at gmail.com> ---
Since write does exactly what is requested (loop over all parameters), it seems
like the only "waste" here is a template instantiation of `write` with the
particular parameters. Such a call is quite benign.

See the code:
https://github.com/dlang/phobos/blob/54eb95c139e09f6e7f8da3beed8407817ba184c1/std/stdio.d#L1750

And this also is going to result in extra instantiations of `write` (all the
ones with single args).

So in some cases, it may actually result in extra instantiations.

In addition, splitting into multiple `write` calls is going to perform worse
(and potentially cause weird outputs) as it locks and unlocks the underlying
`File` for each parameter per call.

Closing as wontfix.

Now, there is a *runtime* penalty that is not discussed here. The fact that all
the parameters need to be pushed again onto the stack, so you can add on the
`\n`.

If there was a better way to handle that, it might be useful to explore.
Perhaps it's not worth fixing, because inlining might already do it.

--


More information about the Digitalmars-d-bugs mailing list