<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body smarttemplateinserted="true">
<div id="smartTemplate4-template">Hi,<br>
<br>
<p>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">1) Implicit cast to ITest which does a runtime lookup (but there's interface name so no string comparison like Supports?)
</pre>
</blockquote>
</p>
<p>just open the disassembler window in Lazarus and single step
through all the instructions. Then you see everything<br>
</p>
<p>create alone calls a bunch of methods:</p>
<p>TInterfacedObject.NewInstance <br>
TObject.NewInstance <br>
getmem<br>
TObject.InitInstance<br>
fillchar<br>
InitInterfacePointers<br>
fpc_pushexceptaddr (on linux only?)<br>
fpc_setjmp<br>
TInterfacedObject.AfterConstruction<br>
</p>
<p><br>
</p>
<p>(interfaces with TInterfacedObject are even worse than
implementing the interface yourself )<br>
</p>
<p>The implicit casting is very fast, a single assembly
instruction: <br>
</p>
<p>add $0x20,%rsi<br>
<br>
</p>
<p>But then it also calls fpc_intf_assign for reference counting</p>
<p><br>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">2) calling "println" there is a call to a wrapper function (called "thunks")?
</pre>
</blockquote>
<br>
</p>
<p>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<br>
</p>
<br>
<br>
<br>
Bye,<br>
Benito </div>
<div class="moz-cite-prefix">On 17.02.21 17:37, Ryan Joseph via
fpc-pascal wrote:<br>
</div>
<blockquote type="cite"
cite="mid:4C8A1105-22A7-44D7-A395-C3A9BC34A13A@gmail.com">
<pre class="moz-quote-pre" wrap="">
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">On Feb 17, 2021, at 8:27 AM, Benito van der Zander via fpc-pascal <a class="moz-txt-link-rfc2396E" href="mailto:fpc-pascal@lists.freepascal.org"><fpc-pascal@lists.freepascal.org></a> wrote:
var c: ITest;
begin
c := TTest.Create(123);
c.println;
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
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 - <a class="moz-txt-link-abbreviated" href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a>
</pre>
</blockquote>
</body>
</html>