Hi,

1) Implicit cast to ITest which does a runtime lookup (but there's interface 
name so no string comparison like Supports?)

just open the disassembler window in Lazarus and single step through all the instructions. Then you see everything

create alone calls a bunch of methods:

TInterfacedObject.NewInstance
TObject.NewInstance
getmem
TObject.InitInstance
fillchar
InitInterfacePointers
fpc_pushexceptaddr (on linux only?)
fpc_setjmp
TInterfacedObject.AfterConstruction


(interfaces with TInterfacedObject are even worse than implementing the interface yourself )

The implicit casting is very fast, a single assembly instruction:

add    $0x20,%rsi

But then it also calls fpc_intf_assign for reference counting


2) calling "println" there is a call to a wrapper function (called "thunks")?

Yes. Basically the wrapper function casts the interface back to the class (sub    $0x20,%rdi) before calling the actual method. Because the class method assumes self is the class and not an interface




Bye,
Benito
On 17.02.21 17:37, Ryan Joseph via fpc-pascal wrote:

On Feb 17, 2021, at 8:27 AM, Benito van der Zander via fpc-pascal 
<fpc-pascal@lists.freepascal.org> wrote:

var c: ITest;
begin
   c := TTest.Create(123);
   c.println;
So this is where you're getting your performance penalties? Correct me if I'm 
wrong but two things happen here:

1) Implicit cast to ITest which does a runtime lookup (but there's interface 
name so no string comparison like Supports?)
2) calling "println" there is a call to a wrapper function (called "thunks")?

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to