Thread overview
More zero-initialization optimizations pending in std.experimental.allocator?
Oct 19, 2018
Per Nordlöw
Oct 20, 2018
Nathan S.
Oct 20, 2018
Stanislav Blinov
Oct 21, 2018
Per Nordlöw
Oct 30, 2018
Nathan S.
October 19, 2018
Now that

    https://github.com/dlang/phobos/pull/6411

has been merged and DMD stable soon has the new

    __traits(isZeroInit, T)

found here

    https://dlang.org/changelog/2.083.0.html#isZeroInit

are there more zero-initializations that can be optimized in std.experimental.allocator?
October 20, 2018
On Friday, 19 October 2018 at 21:29:42 UTC, Per Nordlöw wrote:
> Now that
>
>     https://github.com/dlang/phobos/pull/6411
>
> has been merged and DMD stable soon has the new
>
>     __traits(isZeroInit, T)
>
> found here
>
>     https://dlang.org/changelog/2.083.0.html#isZeroInit
>
> are there more zero-initializations that can be optimized in std.experimental.allocator?

I looked and identified low-hanging fruit in std.mutation.initializeAll & moveEmplace and in std.typecons.RefCounted (PR #6698), and in std.conv.emplaceInitializer (PR #6461). Other opportunities would rely on being able to identify if it's ever more efficient to write `memset(&x, 0, typeof(x).sizeof)` instead of `x = typeof(x).init` which seems like the kind of optimization that belongs in the compiler instead.
October 20, 2018
On Saturday, 20 October 2018 at 15:10:38 UTC, Nathan S. wrote:

> Other opportunities  would rely on being able to identify if it's ever more efficient to write `memset(&x, 0, typeof(x).sizeof)` instead of `x = typeof(x).init` which seems like the kind of optimization that belongs in the compiler instead.

Not unless `mem{set, cpy, move}` etc. are made into compiler intrinsics. Carrying libc dependencies into low-level sensitive code just stinks. If anything, the `memcpy` calls should be removed from `moveEmplace`, not `memset` calls added to it.
They're also not CTFE-able.
October 21, 2018
On Saturday, 20 October 2018 at 15:10:38 UTC, Nathan S. wrote:
>> are there more zero-initializations that can be optimized in std.experimental.allocator?
>
> I looked and identified low-hanging fruit in std.mutation.initializeAll & moveEmplace and in std.typecons.RefCounted (PR #6698), and in std.conv.emplaceInitializer (PR #6461).

What did you search for to find these?

> Other opportunities would rely on being able to identify if it's ever more efficient to write `memset(&x, 0, typeof(x).sizeof)` instead of `x = typeof(x).init` which seems like the kind of optimization that belongs in the compiler instead.

So in which cases is `memset` faster than assignment?

Thanks!
October 30, 2018
On Sunday, 21 October 2018 at 11:09:54 UTC, Per Nordlöw wrote:
> What did you search for to find these?

`typeid` and `.init`.

> So in which cases is `memset` faster than assignment?

I don't know. My guess would be maybe if the type is large, or maybe never. Certainly we'd have to benchmark.