TPersistent overhead

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

TPersistent overhead

Ryan Joseph
What are all the performance costs associated with subclassing TPersistent for RTTI information? I want to use this in some classes but unfortunately the way my code is written I need to basically make all my classes descend from TPersistent, even classes that don’t need RTTI information.

I noticed in my project there is an extra .6 seconds of compile time when I make the changes but are there any other performance costs to consider during runt time or otherwise? I could deal with .6 seconds at compile even though 95% of that is waste but runtime is another story.

Thanks.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TPersistent overhead

Michael Van Canneyt


On Sat, 26 Mar 2016, Ryan Joseph wrote:

> What are all the performance costs associated with subclassing TPersistent
> for RTTI information?  I want to use this in some classes but
> unfortunately the way my code is written I need to basically make all my
> classes descend from TPersistent, even classes that don’t need RTTI
> information.

There is none.

> I noticed in my project there is an extra .6 seconds of compile time when
> I make the changes but are there any other performance costs to consider
> during runt time or otherwise?  I could deal with .6 seconds at compile
> even though 95% of that is waste but runtime is another story.

The overhead is most likely due to writing of RTTI tables.
They are static, and add to the size of the binary, but do not incur speed
penalties.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TPersistent overhead

Graeme Geldenhuys-6
In reply to this post by Ryan Joseph
On 2016-03-26 04:45, Ryan Joseph wrote:
> unfortunately the way my code is written I need to basically make all
> my classes descend from TPersistent, even classes that don’t need
> RTTI information.

Depending on your needs, you don't need to descend from TPersistent just
to get RTTI information in your classes. Simply wrap a TObject
descendant with {$M+} and deactivate the RTTI after the class definition.

For example:

  {$M+}
  TtiVisited = class(TObject)
    ... define your class interface here...
  end;
  {$M-}


Now TtiVisited will have RTTI information compiled in.

Regards,
  - Graeme -

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TPersistent overhead

Ryan Joseph
In reply to this post by Ryan Joseph
Great, thanks Michael.

I had another idea. Is it really required to subclass TPersistent for RTTI information or can I just use {$M+} on the units that I need and leave the class hierarchy the same?

> On Mar 26, 2016, at 6:00 PM, [hidden email] wrote:
>
> On Sat, 26 Mar 2016, Ryan Joseph wrote:
>
>> What are all the performance costs associated with subclassing TPersistent
>> for RTTI information?  I want to use this in some classes but
>> unfortunately the way my code is written I need to basically make all my
>> classes descend from TPersistent, even classes that don?t need RTTI
>> information.
>
> There is none.
>
>> I noticed in my project there is an extra .6 seconds of compile time when
>> I make the changes but are there any other performance costs to consider
>> during runt time or otherwise?  I could deal with .6 seconds at compile
>> even though 95% of that is waste but runtime is another story.
>
> The overhead is most likely due to writing of RTTI tables.
> They are static, and add to the size of the binary, but do not incur speed
> penalties.
>
> Michael.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TPersistent overhead

Michael Van Canneyt


On Sun, 27 Mar 2016, Ryan Joseph wrote:

> Great, thanks Michael.
>
> I had another idea. Is it really required to subclass TPersistent for RTTI information or can I just use {$M+} on the units that I need and leave the class hierarchy the same?

Using

{$M+}

For classes that need RTTI is sufficient. I do this myself.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TPersistent overhead

Ryan Joseph
In reply to this post by Ryan Joseph
Good idea thanks.

> On Mar 27, 2016, at 5:00 PM, [hidden email] wrote:
>
> Depending on your needs, you don't need to descend from TPersistent just
> to get RTTI information in your classes. Simply wrap a TObject
> descendant with {$M+} and deactivate the RTTI after the class definition.
>
> For example:
>
>  {$M+}
>  TtiVisited = class(TObject)
>    ... define your class interface here...
>  end;
>  {$M-}

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal