[fpc-devel] (patch) improvement of object creation speed

Sergei Gorelkin sergei_gorelkin at mail.ru
Tue May 20 14:31:27 CEST 2008


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.zip
Type: application/x-zip-compressed
Size: 4046 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20080520/015519dd/attachment.bin>


More information about the fpc-devel mailing list