[fpc-devel] Faster InitObject

Amir amir at aavani.net
Thu Feb 23 08:47:33 CET 2012


    I have a code, developed in object pascal, with many classes. The
project is working fine.
    Today, I used callgrind (valgrind --tool=calgrind) to see which
function consumes the most execution time and I noticed that the most of
time in my project is consumed by fillchar function.

Incl.   Self.   Called     Function
29.78   29.72    26M        SYSTEM_FILLCHAR$formal$INT64$BYTE
19.07   19.07    123M       SYSTEM_MOVE$formal$formal$INT64
   3.63    3.63    70M       SYSTEM_SYSGETMEM_FIXED$QWORD$$POINTER

The main caller of FillChar function is
system_TObject_$__NewInstance$$TObject which called Fillchar 26 Million

NewInstance method in TObject calls InitInstance which is an inline
function and defined as follows:

        class function TObject.InitInstance(instance : pointer) :
tobject; {$ifdef SYSTEMINLINE} inline; {$ENDIF}

             { the size is saved at offset 0 }
             fillchar(instance^, InstanceSize, 0);
             { insert VMT pointer into the new created memory area }
             { (in class methods self contains the VMT!)           }
             if PVmt(self)^.vIntfTable <> @emptyintf then

My question is do we need to call fillchar in InitInstance? Or Is there
any way to avoid calling InitInstance?


P.S. I can send you the output of callgrind.

More information about the fpc-devel mailing list