[fpc-devel] Optimization for TObject.InheritsFrom (and the 'is' operator)

Bram Kuijvenhoven kuifwaremailinglists at xs4all.nl
Sun Jul 22 23:47:06 CEST 2007


Florian Klaempfl wrote:
> Just curious, did anybody have profiling results which indicate that
> as/is are really a bottleneck?

Though it can heavily depend on the particular application, the results for a large project I'm working on is as follows:

(Used tool: valgrind-callgrind, FPC 2.1.4, i386, Debian Sarge)

105,233,754  PROGRAM TOTALS

6,417,954  ???:0x00071C80 [/lib/libc-2.3.2.so]
5,350,079  ???:malloc [/lib/libc-2.3.2.so]
4,918,460  ???:fpc_ansistr_setlength
4,687,338  ???:0x00072260 [/lib/libc-2.3.2.so]
4,471,026  <snip>
4,458,735  ???:free [/lib/libc-2.3.2.so]
3,588,596  ???:fpc_pushexceptaddr
3,375,706  ???:fpc_ansistr_decr_ref
3,287,077  ???:SYSTEM_READPCHARLEN$TEXT$PCHAR$LONGINT$$LONGINT
3,099,242  ???:fpc_popaddrstack
2,609,888  ???:SYSTEM_SETJMP$JMP_BUF$$LONGINT
2,237,355  <snip>
2,180,774  <snip>
2,108,772  ???:CMEM_CGETMEM$LONGINT$$POINTER
2,082,456  ???:realloc
1,860,684  ???:fpc_ansistr_concat
1,847,952  ???:0x000725B0 [/lib/libc-2.3.2.so]
1,807,053  ???:SYSTEM_UPCASE$CHAR$$CHAR
1,767,843  ???:SYSTEM_UPCASE$SHORTSTRING$$SHORTSTRING
1,743,218  <snip>
1,664,880  ???:CMEM_CFREEMEM$POINTER$$LONGINT
1,648,998  ???:fpc_ansistr_compare_equal
1,438,248  ???:SYSTEM_GETMEM$POINTER$LONGINT
1,332,799  ???:SYSTEM_FREEMEM$POINTER$$LONGINT
1,328,215  <snip>
1,284,030  <snip>
1,239,614  ???:fpc_ansistr_copy
1,189,035  ???:SYSTEM_TOBJECT_$__INHERITSFROM$TCLASS$$BOOLEAN  !!! Here it is !!!
1,046,717  ???:CMEM_CREALLOCMEM$POINTER$LONGINT$$POINTER
1,023,076  ???:0x00015C8D [/lib/libc-2.3.2.so]
  837,834  <snip>
  788,966  <snip>
  764,608  ???:fpc_ansistr_incr_ref
  762,624  ???:SYSTEM_MOVE$formal$formal$LONGINT

(<snip> means its a routine from my app.)

The application does not have a very deep inheritance tree (when compared with e.g. the LCL). It uses 'is'/'as' at some places where polymorphism cannot be used. (Comparable with situations like TPersistent.Assign)

The above shows that it takes a reasonable amount of time (about 1.1%), comparable with some of the other 'time-eaters'. I also profiled with other input files, and the results varied, depending on which part of the program was getting focus (e.g. parsing input files (1.6%), or processing image files (0.4%)).


More profiling could be done to get a more objective point of view, so everyone is invited to provide his or her results :)

Still, I think the above already shows that InheritsFrom is worth /some/ attention.


Regards,

Bram



More information about the fpc-devel mailing list