On 5/24/17 12:40 PM, Andrei Alexandrescu wrote:
On 5/24/17 4:49 PM, Steven Schveighoffer wrote:
On 5/23/17 3:47 PM, Andrei Alexandrescu wrote:
https://github.com/dlang/phobos/pull/5421
Looking forward to more in the same vein, please contribute! We have 25
left in phobos and 12 in druntime. A big one will be making the GC
lazily initialize itself. -- Andrei
So every time I do:
writeln(...)
It has to go through a check to see if it's initialized? Using a
delegate?
The delegate is not called in the steady state.
OK, I worry about inlineability as DMD has issues when you are using
delegates sometimes. Unfortunately, I think the compiler isn't smart
enough to realize that after one check of the boolean returns true, it
could just access the File handle directly.
Has the performance of this been tested?
Always a good idea. My test bed:
void main()
{
import std.stdio;
foreach (i; 0 .. 10_000_000) writeln("1234567890");
}
On my laptop using dmd, phobos master, best of 21 runs using "time test
/dev/null": 1.371 seconds.
With initOnce: 1.469 seconds. Yuck!
So I added double checking:
https://github.com/dlang/phobos/pull/5421/commits/6ef3b5a6eacfe82239b7bbc4b0bc9f38adc6fe91
With the double checking: 1.372 seconds. So back to sanity.
Thanks for asking me to measure!
This is pretty decent. I still prefer the static ctor solution, but this
is workable.
-Steve