[fpc-devel] rtti, arrays and performance
Michael Van Canneyt
michael at freepascal.org
Fri Oct 6 22:01:55 CEST 2006
On Fri, 6 Oct 2006, Vlad wrote:
> Hi.
>
> I'm porting my Delphi app to Mac OS X. Fortunately my core classes compile fine with freepascal, so I can produce dylib and use it from Cocoa application. To make binaries I use fpc 2.0.4 for powerpc version and fpc 2.1.1 for intel version (2.1.1 snapshot downloaded on August 2, 2006 from lazarus section). Recently I started to test performance and found that rtl spends quite a lot of time on array finalization. If you look into rtti.inc file you may see that it walks on array and trying to finalize each item even though it may need no finalization at all. Same with dynamic arrays. And with dynamic arrays similar problem may happen if rtl needs to add reference to each item in array but of cource it could be that items are not reference counted, so it will walk on array and will call appropriate function which just have nothing to do. To solve this issue I added function into "rtti.inc" which determines is data type dynamic (and therefore needs finalization and could be refrence counted) or not. It just recursively checks data types and returns TRUE if data type needs finalization. Then in ArrayRTTI and fpc_finalize_array I call this function to check is it neccessary to finalize each item or not. I added this function to "aliases.inc" and use it from "dynarr.inc" too - there two places where int_addref() function called for each array item, so, before doing this now for me it checks is that neccessary or not.
Did you see a change in performance ? Can you give an order of magnitude ?
>
> Perhaps the best way is to include some kind of attribute into type info and determine at compile time is data type has any dynamic part or not. Perhaps compiler may even not generate finalization calls for records (I don't know - maybe this is already done in compiler). But this could be much bigger amount of work
>
> I can provide more info if you need. And I think that even such change is already better than nothing...
I think it may be indeed a better idea to see whether the compiler can set a flag in the type info:
If we change TTypeInfo to
TTypeInfo = record
Kind : TTypeKind;
Finalize : Boolean;
Name : ShortString;
// here the type data follows as TTypeData record
end;
Then there is no need for a recursive loop (the compiler has already done that...);
Only the Finalize field needs to be retrieved. Putting this field in the middle will
make sure 99,9% of all existing code will still work.
Peter, Florian, any comments ?
Michael.
More information about the fpc-devel
mailing list