[fpc-pascal] Traits Proposal

Sven Barth pascaldragon at googlemail.com
Tue Feb 16 23:38:43 CET 2021


Benito van der Zander via fpc-pascal <fpc-pascal at lists.freepascal.org>
schrieb am Di., 16. Feb. 2021, 23:35:

> Interfaces are not slow because they are are interfaces! When you call a
> interface method it has the same costs as a virtual method call! And the
> cost for reference counting that interfaces have right now would be there
> for ARC as well.
>
>
> But it is not calling the method, it is calling the wrapper function
>
> That is a additional second method call/jump for every interface method
> call.
>
>
> E.g. _AddRef on TInterfacedObject as an interface, does not call
> TInterfacedObject._AddRef, it calls this:
> WRPR_$SYSTEM_$$_TINTERFACEDOBJECT_$_IUNKNOWN_$_1_$_SYSTEM$_$TINTERFACEDOBJECT_$__$$__ADDREF$$LONGINT
>
> 0000000000424600 4883ef10                 sub    $0x10,%rdi
> 0000000000424604 e997f8feff               jmpq   0x413ea0
> <SYSTEM$_$TINTERFACEDOBJECT_$__$$__ADDREF$$LONGINT>
>

It's an *unconditional* jump. The branch prediction of the CPU should
handle this without much penalty.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210216/8001169d/attachment.htm>


More information about the fpc-pascal mailing list