Thread overview
Simplifying druntime and phobos by getting rid of "shared static this()" blocks
May 23, 2017
David Nadlinger
May 24, 2017
Stanislav Blinov
May 23, 2017
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
May 23, 2017
On Tuesday, 23 May 2017 at 19:47:49 UTC, Andrei Alexandrescu wrote:
> A big one will be making the GC lazily initialize itself.

How detailed are your plans for this? The interaction between GC and shared library loading is a bit non-trivial to get right. — David


May 23, 2017
On 05/23/2017 04:34 PM, David Nadlinger wrote:
> On Tuesday, 23 May 2017 at 19:47:49 UTC, Andrei Alexandrescu wrote:
>> A big one will be making the GC lazily initialize itself.
> 
> How detailed are your plans for this? The interaction between GC and shared library loading is a bit non-trivial to get right. — David

Not too detailed, and that why I'm counting for experts such as yourself. -- Andrei

May 23, 2017
On 05/23/2017 03: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

In the same vein: https://github.com/dlang/phobos/pull/5423 -- Andrei
May 24, 2017
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?

Has the performance of this been tested?

I agree the stdiobase thing is ugly. We could also fix this by improving the cycle detection mechanism (e.g. you could tag the static ctor that initializes the handles to say it doesn't depend on any other static ctors, and just put it in stdio).

-Steve
May 24, 2017
On 5/23/17 4:42 PM, Andrei Alexandrescu wrote:
> On 05/23/2017 03: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
>
> In the same vein: https://github.com/dlang/phobos/pull/5423 -- Andrei

This one I 100% agree with!

-Steve
May 24, 2017
On Wednesday, 24 May 2017 at 15:49:58 UTC, 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?

It also copies every argument four times.



May 24, 2017
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.

> 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!


Andrei
May 24, 2017
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
May 24, 2017
BTW the best outcome of this is a faster initOnce. Steve, take a look at it pliz pliz? -- Andrei