On Sunday, 30 March 2014 at 01:42:24 UTC, Walter Bright wrote:
On 3/29/2014 6:11 PM, deadalnix wrote:
I'm talking about interface here. The way they are implemented
in most new
language is via a struct that contains:
- pointer to the object
- pointer to vtable
That way to don't make object bigger when they implement an
interface,
True, but why is this a problem?
Higher memory consumption, less objects fitting in cache, more
scanning to do for the GC.
and you don't need cascaded load to call methods.
True, but on the other hand, it takes up 2 registers rather
than one, costing twice as much to copy around, store,
pass/return to functions, etc.
Two pointers structs are passed in register, which is fast. If
that spill, that spill on stack, which is hot, and prefetcher
friendly.
On the other hand, the double indirection is very cache
unfriendly.