Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-03

TPersistent overhead

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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

Michael Van Canneyt
to Ryan Joseph
Ryan Joseph wrote 5 lines
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.

Graeme Geldenhuys
to Ryan Joseph: What are all the performance costs associated with subclassing TPersistent for RTTI…
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
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?

Show quoted text 22 lines
On Mar 26, 2016, at 6:00 PM, 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

Michael Van Canneyt
to Ryan Joseph
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.

Ryan Joseph

Good idea thanks.

Show quoted text 13 lines
On Mar 27, 2016, at 5:00 PM, 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