Sign in Join

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

Mailing lists / fpc-devel / 2008-05

(patch) improvement of object creation speed

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Sergei Gorelkin

Hello,

While valgrinding my projects, I noticed that InitInterfacePointers procedure eats noticeable amount of CPU cycles. For TObject.NewInstance call tree, I got Irefs for GetMem and InitInterfacePointers relating approx. as 42/36, i.e. InitInterafacePointers only a bit faster than GetMem. What's worse, in projects that do not use interfaces (like the compiler itself), InitInterfacePointers is nothing but a waste of time.

I addressed this in two ways:

1) Declaring VMT as a record and rewriting related objpas.inc code in plain Pascal style (without typecasts) cuts down Irefs of InitInterfacePointers twice (36 becomes 17). The similar effect is probably achieved on other TObject methods - but I did not benchmark that explicitly.
It also makes the code *much* more readable.

2) Modified the compiler to write a special value (FPC_EMPTYINTF) to vmtIntfTable field of the VMT when neither the class nor any of its ancestors implement interfaces. FPC_EMPTYINTF points to an interface table with zero entries. This way, it's possible to break out of the interface lookup as soon as it's known that nothing can be found (and it can omit InitInterfacePointers altogether in relevant cases).

There are also some minor changes, like {$IMPLICITEXCEPIONS OFF} around TObject.Create (nothing can cause an exception in an empty method), inlining call to TObject.ClassName in TObject.ClassNameIs (eliminates local variable and string copy).

Best regards,
Sergei

Reply by email

Florian Klaempfl
to Sergei Gorelkin
Show quoted text 11 lines
Hello, While valgrinding my projects, I noticed that InitInterfacePointers procedure eats noticeable amount of CPU cycles. For TObject.NewInstance call tree, I got Irefs for GetMem and InitInterfacePointers relating approx. as 42/36, i.e. InitInterafacePointers only a bit faster than GetMem. What's worse, in projects that do not use interfaces (like the compiler itself), InitInterfacePointers is nothing but a waste of time. I addressed this in two ways:

Thanks, applied.

There are also some minor changes, like {$IMPLICITEXCEPIONS OFF} around TObject.Create (nothing can cause an exception in an empty method),

I remove this part, the compiler handles this now in a generic way by replacing

try
finally
   statement
end;

by

statement;

Reply by email