www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7243] New: Compiler should call separate function when allocating a struct on the heap

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7243

           Summary: Compiler should call separate function when allocating
                    a struct on the heap
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: schveiguy yahoo.com



12:00:56 PST ---
Note, this requires druntime fixes too, but I can't select both DMD and
druntime.


Currently, when creating a struct on the heap, _d_newarrayT is called with a
length of 1.

However, the runtime must assume this is an array of length 1.  Therefore, it
must set the appendable bit, and reserve space for the 'used' length.

This can waste space.

For instance, the following could fit in a 16-byte block, but will go into a
32-byte block due to the used field:

import core.memory;

struct S
{
  int[4] buf;
}

void main()
{
  auto s = new S;
  assert(GC.sizeof(s) == 32);
}

I think instead, a _d_newstruct function should be called (and implemented in
druntime) to initialize a single struct on the heap in the most efficient
manner possible.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 07 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7243




11:29:39 PDT ---
Martin Nowak has found a very compelling case for this to be fixed, it is
affecting performance of RedBlackTree.

From bug 5650:

When in 64-bit mode, each pointer is 8 bytes.  RedBlackNodes have a left,
right, and parent pointer, consuming 24 bytes.  Then it contains the payload,
followed by a byte for the color (red or black).  The basic RedBlackTree!int
case has a payload of int, or 4 bytes.  With alignment padding, this brings the
size of the struct to 32 bytes.

Now, given that array appending needs the extra byte for 'used' length (also
serves as a sentinel to prevent accidentally accessing the subsequent block),
this will be with array padding, 33 bytes, pushing the block required to 64
bytes.

Not only that, but because the struct has pointers, it must zero out those 31
unused bytes.

With his measurements as quoted in bug 5650, fixing this problem resulted in
roughly a 40% runtime reduction.

Can we please get this fixed?  I'll be happy to implement the druntime function
if someone will take care of the compiler part.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7243




Commit pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/c8897db61b76f4f2eac12581042adcfb35543bd4
fix Issue 7243 - Compiler should call separate function when allocating a
struct on the heap

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7243




Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/4004bb3b222676c74a41c0bb2507979963167457
fix Issue 7243 - Compiler should call separate function when allocating a
struct on the heap

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7243


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



14:06:50 PDT ---
Back to you, Steven!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7243




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/a766e4a395e4fb86ff31c6161d343d85805d96b3
fix Issue 7243 - Compiler should call separate function when allocating a
struct on the heap

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7243


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |



07:56:53 PDT ---
Added pull request: https://github.com/D-Programming-Language/druntime/pull/202

Note that this isn't technically fixed until this pull request is incorporated.
 Also, I'm not sure this should affect D1, thoughts?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 30 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7243




Commit pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/7375e9098e7852cd333d3ed6d211aa3eaf719352


Implement druntime functions for allocating individual structs on the heap.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 11 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7243


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 11 2012