[fpc-devel] Need heap manager -gv explanation [tests]

Petr Kristan petr.kristan at epos.cz
Tue Apr 29 10:30:43 CEST 2014


On Mon, Apr 28, 2014 at 09:29:50PM +0200, Mattias Gaertner wrote:
> On Mon, 28 Apr 2014 21:14:14 +0200
> Petr Kristan <petr.kristan at epos.cz> wrote:
> 
> >[...]
> > > Others would be better positioned for more detailed comparison among
> > > various heap managers with regard to speed in different use cases, overall
> > > memory requirements achieved by reuse of previously allocated memory, etc.
> > Reuse of previously allocated memory - it really can be my problem.
> > Here is about 200x call ReAllocMem increasing buffer from 4kB to 80MB.
> 
> Check if you are increasing buffers in constant steps.
> Change the increment to exponentially.
I use "inteligent" block increasing. I can optimize program, but why is
fpc heap manager to slow?

Here is the sample stress program compilable with fpc, delphi and kylix:

program m;
{$IFDEF MSWINDOWS}
  {$APPTYPE CONSOLE}
{$ENDIF}

uses
{$IFDEF MSWINDOWS}
  Windows,
{$ELSE}
  {$IFDEF FPC}
  Unix,
  {$ELSE}
  Libc,
  {$ENDIF}
{$ENDIF}
  SysUtils;

{$IFDEF MSWINDOWS}
function GetTickCount: Cardinal;
begin
  GetTickCount := Windows.GetTickCount;
end;
{$ELSE}
  {$IFDEF FPC}
  function GetTickCount: Cardinal;
  var
    tp: TTimeVal;
  begin
    fpgettimeofday(@tp, nil);
    GetTickCount := (Int64(tp.tv_sec) * 1000) + (tp.tv_usec div 1000);
  end;
  {$ELSE}
  function GetTickCount: Cardinal;
  var
    ts: TTimeSpec;
    i: Int64;
  const
    CLOCK_MONOTONIC = 1;
  begin
    if clock_gettime(CLOCK_MONOTONIC, ts) <> 0 then begin
      Result := 0;
      Exit;
    end;
    i := ts.tv_sec;
    i := i*1000 + ts.tv_nsec div 1000000;
    Result := i and $ffffffff;
  end;
  {$ENDIF}
{$ENDIF}

var
  p1, p2: Pointer;
  i, j: integer;
  ms, sum: Cardinal;
const
  base = 1000000;
begin
  sum := GetTickCount;
  for i := 0 to 10 do begin
    ms := GetTickCount;
    for j := 1 to 9 do begin
      ReAllocMem(p1, base*(i*10+j));
      ReAllocMem(p2, base*(i*10+j));
    end;
    Writeln(Format('Grow %d-%d %dms', [base*i*10, base*(i*10+9), GetTickCount-ms]));
  end;
  FreeMem(p1);
  FreeMem(p2);
  Writeln(Format('Sum %dms', [GetTickCount-sum]));
end.

--------------------------------------------------------------------------------
And here are results:

ppcx64 m.pas
Free Pascal Compiler version 2.7.1 [2014/02/17] for x86_64
Target OS: Linux for x86-64
Grow 0-9000000 89ms
Grow 10000000-19000000 281ms
Grow 20000000-29000000 488ms
Grow 30000000-39000000 716ms
Grow 40000000-49000000 898ms
Grow 50000000-59000000 1085ms
Grow 60000000-69000000 1294ms
Grow 70000000-79000000 1470ms
Grow 80000000-89000000 1652ms
Grow 90000000-99000000 1916ms
Grow 100000000-109000000 2099ms
Sum 12007ms

ppcx64 -gv m.pas
Free Pascal Compiler version 2.7.1 [2014/02/17] for x86_64
Target OS: Linux for x86-64
Grow 0-9000000 0ms
Grow 10000000-19000000 0ms
Grow 20000000-29000000 1ms
Grow 30000000-39000000 0ms
Grow 40000000-49000000 0ms
Grow 50000000-59000000 0ms
Grow 60000000-69000000 2ms
Grow 70000000-79000000 3ms
Grow 80000000-89000000 2ms
Grow 90000000-99000000 0ms
Grow 100000000-109000000 0ms
Sum 10ms

ppc386 m.pas
Free Pascal Compiler version 2.7.1 [2013/06/28] for i386
Target OS: Linux for i386
Grow 0-9000000 86ms
Grow 10000000-19000000 247ms
Grow 20000000-29000000 417ms
Grow 30000000-39000000 595ms
Grow 40000000-49000000 781ms
Grow 50000000-59000000 964ms
Grow 60000000-69000000 1128ms
Grow 70000000-79000000 1288ms
Grow 80000000-89000000 1438ms
Grow 90000000-99000000 1612ms
Grow 100000000-109000000 1767ms
Sum 10341ms

ppc386 -gv m.pas
Free Pascal Compiler version 2.7.1 [2013/06/28] for i386
Target OS: Linux for i386
Grow 0-9000000 0ms
Grow 10000000-19000000 0ms
Grow 20000000-29000000 0ms
Grow 30000000-39000000 0ms
Grow 40000000-49000000 0ms
Grow 50000000-59000000 0ms
Grow 60000000-69000000 1ms
Grow 70000000-79000000 0ms
Grow 80000000-89000000 0ms
Grow 90000000-99000000 0ms
Grow 100000000-109000000 0ms
Sum 1ms

dcc m.pas
Borland Delphi for Linux Version 14.5
Grow 0-9000000 0ms
Grow 10000000-19000000 0ms
Grow 20000000-29000000 0ms
Grow 30000000-39000000 0ms
Grow 40000000-49000000 0ms
Grow 50000000-59000000 0ms
Grow 60000000-69000000 0ms
Grow 70000000-79000000 0ms
Grow 80000000-89000000 0ms
Grow 90000000-99000000 0ms
Grow 100000000-109000000 0ms
Sum 2ms

fpc m.pas
Free Pascal Compiler version 2.7.1 [2013/12/27] for i386
Target OS: Win32 for i386
Grow 0-9000000 47ms
Grow 10000000-19000000 157ms
Grow 20000000-29000000 359ms
Grow 30000000-39000000 531ms
Grow 40000000-49000000 656ms
Grow 50000000-59000000 797ms
Grow 60000000-69000000 985ms
Grow 70000000-79000000 1109ms
Grow 80000000-89000000 1250ms
Grow 90000000-99000000 1406ms
Grow 100000000-109000000 1532ms
Sum 8829ms

dcc m.pas
Borland Delphi Version 15.0
Grow 0-9000000 16ms
Grow 10000000-19000000 31ms
Grow 20000000-29000000 47ms
Grow 30000000-39000000 47ms
Grow 40000000-49000000 109ms
Grow 50000000-59000000 63ms
Grow 60000000-69000000 62ms
Grow 70000000-79000000 250ms
Grow 80000000-89000000 266ms
Grow 90000000-99000000 94ms
Grow 100000000-109000000 110ms
Sum 1125ms

(Windows is virtual machine)

Is possible to speedup heap manager?

Petr

-- 
Petr Kristan
.
EPOS PRO s.r.o., Smilova 333, 530 02 Pardubice
tel: +420 461101401    Czech Republic (Eastern Europe)
fax: +420 461101481



More information about the fpc-devel mailing list