Why aren't Ranges Interfaces?

rsw0x via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 26 12:40:40 PDT 2015


On Friday, 26 June 2015 at 19:26:57 UTC, Jack Stouffer wrote:
> Thanks for the reply! I understand the reasoning now.
>
> On Friday, 26 June 2015 at 18:46:03 UTC, Adam D. Ruppe wrote:
>> 2) interfaces have an associated runtime cost, which ranges 
>> wanted to avoid. They come with hidden function pointers and 
>> if you actually use it through them, you can get a performance 
>> hit.
>
> How much of a performance hit are we talking about? Is the 
> difference between using an interface and not using one 
> noticeable?

It can be in a tight loop.

http://eli.thegreenplace.net/2013/12/05/the-cost-of-dynamic-virtual-calls-vs-static-crtp-dispatch-in-c

this is for C++, but it applies directly to D. Interestingly, 
CRTP is a gigantic C++ hack that D gets for free with alias this.


More information about the Digitalmars-d-learn mailing list