Discussion Thread: DIP 1042--ProtoObject--Community Review Round 1
bauss
jj_1337 at live.dk
Fri Jan 14 08:00:30 UTC 2022
On Friday, 14 January 2022 at 03:38:28 UTC, tsbockman wrote:
> On Monday, 10 January 2022 at 13:48:14 UTC, Mike Parker wrote:
>> This is the discussion thread for the first round of Community
>> Review of DIP 1042, "ProtoObject":
>>
>> https://github.com/dlang/DIPs/blob/2e6d428f42b879c0220ae6adb675164e3ce3803c/DIPs/DIP1042.md
>
> One issue with this DIP that I haven't noticed anyone else
> raise yet is interface bloat. Each interface directly
> implemented by a class or any of its super classes adds
> `size_t.sizeof` to the instance size:
>
> ```D
> module app;
>
> import std.stdio : writeln;
>
> interface Stringify { }
> interface Hash { }
> interface Ordered { }
> interface Equals { }
>
> class D : Stringify, Hash, Ordered, Equals { }
>
> void main() {
> writeln("Object instance size: ",
> __traits(classInstanceSize, Object));
> writeln("D instance size: ", __traits(classInstanceSize,
> D));
> }
> ```
>
> Output:
> ```
> Object instance size: 16
> D instance size: 48
> ```
>
> We care enough about minimizing instance size to fret about 8
> bytes wasted on an unused mutex, but then burden all new-style
> classes that need full compatibility with the standard library
> with up to 32 bytes of interface implementations. This does not
> seem like an improvement to me.
>
> Single method interfaces are an anti-pattern for lightweight
> classes, given how D implements interfaces.
This is a very important point because in general that could
bloat your memory by A LOT. In your example the bloat is 3 times
as much. So I'n going to guess this DIP in reality will add maybe
2-3 times as much bloat when implemented with functionality
within those interfaces etc.
That's just terrible.
More information about the Digitalmars-d
mailing list