Why can't D language framework play best?

welkam wwwelkam at gmail.com
Mon May 11 11:03:26 UTC 2020


On Monday, 11 May 2020 at 08:09:24 UTC, Jacob Carlborg wrote:
> It seems very class centric.
The problem with classes is that they introduce indirections. 
First they are reference type so any access to them goes trough a 
pointer. Second unless you marked methods as final method calls 
goes trough vtable  meaning that to execute a code on a peace of 
data it could require 2 pointer "derefrences".

I dont know how GC allocates memory but malloc gives 16 byte 
aligned pointers and if GC does the same then if your class size 
is not multiple of 16 you would get a lot of "padding" between 
your classes. Since processor loads 64 bytes at a time you are 
guarantee that padding will be loaded too wasting cache space and 
bandwidth. Better to use containers that put data in contiguous 
peace of memory.

You can get most of what class inheritance gives by using alias 
this on structs.
struct example {
     base foo;
     alias foo this;
}
struct base {//data}

Jacob is correct to point out that memory management should not 
be overlooked. DMD got a big improvement when it switched to bump 
the pointer allocator
https://www.drdobbs.com/cpp/increasing-compiler-speed-by-over-75/240158941

After this article I read another blog post that was inspired by 
this and preallocated a bunch of memory and saw over 100% speed 
improvement.

Because we dont have profile information our advice can only be 
vague and not specific.


More information about the Digitalmars-d mailing list