[fpc-pascal] Traits Proposal
Benito van der Zander
benito at benibela.de
Tue Feb 16 23:35:06 CET 2021
Hi,
> If you need to create 1000 class instances each frame then you have a
> flaw in your logic in my opinion.
>
I have more like a million class instances
For my XPath stuff, and every returned value is put in a variant-like
class. Selecting all nodes on an GB large XML, could even create almost
a billion class instances
I once did a benchmark. It is 10% faster to reuse the class instances
rather than recreating them, my commit log says. And I only implemented
one interface (actually, two interfaces, since IUnknown always gets
pulled in, too. )
> 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>
Bye,
Benito
On 16.02.21 19:48, Sven Barth via fpc-pascal wrote:
> Ryan Joseph via fpc-pascal <fpc-pascal at lists.freepascal.org
> <mailto:fpc-pascal at lists.freepascal.org>> schrieb am Di., 16. Feb.
> 2021, 19:21:
>
> >
> > There we have:
> >
> > * slower creation of the class, because each implemented
> interface adds another VMT reference to the class which needs to
> be initialized.
>
> How bad is this? We need to make a test case we can profile. For
> example if you have a game that creates 1000 classes 60 frames per
> second. If adding interfaces to the classes hurts this process we
> may have a deal breaker.
>
>
> If you need to create 1000 class instances each frame then you have a
> flaw in your logic in my opinion.
>
>
> > * slow reference counting. Especially if it is thread safe and
> exception safe with the implicit exception block
>
> It's a whole other topic but FPC needs opt-in ARC at the language
> level for classes. Interfaces are not only slow but then you need
> to pass around a reference to the interface instead of the class
> you actually care about. It makes no sense to me whatsoever.
>
>
> 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.
>
> Regards,
> Sven
>
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210216/ec3af497/attachment-0001.htm>
More information about the fpc-pascal
mailing list