[fpc-devel] TList slowness in classes

Michalis Kamburelis michalis at camelot.homedns.org
Fri Dec 24 05:17:29 CET 2004


Hi,

I tested your code and found that indeed version in ucopylist is 
slightly faster (by about 9.5 / 7 =~ 1.357). Two things:

1. Speedup is only 1.357x, not 3x, like you said. Are you sure that 
you're getting 3x speedup ? On what OS and with what FPC version are you 
testing this ? I was doing tests with Linux/i386 with FPC 1.9.4 and 
1.9.5 (from CVS 2004-12-20).

2. Still, speedup 1.357x may be significant in some cases so I 
investigated what's the cause:

After many tests I found that this slight speedup is caused by the fact 
that in ucopylist you declared string constants SListIndexError, 
SListCapacityError and SListCountError as normal constants while with 
original Classes unit these constants are taken from RTLConst unit that 
defines them as resourcestrings.

Using resourcestrings in RTL is a must, since this allows to translate 
error messages without modifying unit Classes sources.

However in this case exceptions are not raised, so resourcestrings are 
not actually used. But it looks that any procedure that uses some 
resourcestring in implementation is doomed to be slower than the similar 
procedure that instead uses normal string consts, *even if this 
procedure doesn't actually access the string at runtime*. It seems that 
if some procedure uses resourcestring then upon entry it does some 
lengthy initialization of this resourcestring, even if it will not 
actually make use of that resourcestring.

I'm attaching a simple demo program that shows this. When compiled like
   fpc -OG -O2 -Op2 demo_resourcestring_slow.pas
(to get maximum optimizations) sample output of it is
   Time of Foo_Normal:         16
   Time of Foo_ResourceString: 106
So time difference is really noticeable. Question goes to FPC 
developers, maybe such cases with using resourcestrings can be speed up ?

Regards,
-- 
Michalis

Ales Katona wrote:
> I've read a complaint about TList being slow so I decided to give it a 
> test.
> Quite frankly the test showed this is truth, but I couldn't find out why.
> I found out that if I copy the TList from classes "as-is" into my unit 
> and use this
> copy, it is about 3x faster in certain conditions. I have no idea why 
> this is so but
> I think there's something wrong...
> 
> I posted my test at http://members.chello.sk/ales/testlist.zip
> Just download, unzip and compile:
> you'll get swap time and access time for the original TList
> uncomment {$DEFINE USEMYLIST} to get the times for my copy of TList
> 
> The copy there is unchanged.
> 
> Ales Katona
> 
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: demo_resourcestring_slow.pas
Type: text/x-pascal
Size: 1195 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20041224/7dc37434/attachment.pas>


More information about the fpc-devel mailing list