www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - More zero-initialization optimizations pending in

reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
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?
Oct 19 2018
parent reply Nathan S. <no.public.email example.com> writes:
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 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.
Oct 20 2018
next sibling parent Stanislav Blinov <stanislav.blinov gmail.com> writes:
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.
Oct 20 2018
prev sibling parent reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
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
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!
Oct 21 2018
parent Nathan S. <no.public.email example.com> writes:
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.
Oct 30 2018