Why can't D language framework play best?
IGotD-
nise at nise.com
Mon May 11 11:44:07 UTC 2020
On Monday, 11 May 2020 at 11:03:26 UTC, welkam wrote:
> 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.
This is one of my biggest discontents with the D design, that
classes are forced to be reference types (it is actually a value
type where the pointer is wrapped in the base object struct). The
only way to have class expanded in the host class is to use
struct, but struct is limited in many ways.
Classes expanded in host classes has worked well in C++ so I
don't really understand the design decision here. Allocated
member classes can sometimes be beneficial in terms of resource
handling (used in several classes for example) but in the
majority of the times it is better to expand in the class.
So if a class as several member classes, all of them needs to be
allocated which takes its toll on the performance. It's kind of a
Java-ish approach but it certainly has its performance drawbacks.
There have been discussions to increase the capabilities of
struct so that it can match class better so that people can use
struct more but these changes have been denied.
More information about the Digitalmars-d
mailing list