Skip to content

Catastrofic slowdown when deleting 600k items in TFPGList

how issue appeared in the wild (in CudaText editor): https://synwrite.sourceforge.net/forums/viewtopic.php?t=3126

repro program: attached. test.zip

its output on Intel Core i3 3GHz:

time to fill list: 82ms
time to clear list: 335570ms

how to fix it: rtl/objpas/fgl.pp, in procedure TFPSList.Delete(Index: Integer); replace

FillChar(InternalItems[FCount]^, (FCapacity+1-FCount) * FItemSize, #0);

with

FillChar(InternalItems[FCount]^, FItemSize, #0);

it must fill only one last item. currently: it fills the big gap, from last item to the Capacity. for 600k items:

  • fillchar 1 item
  • fillchar 2 items
  • fillchar 3 items
  • ...
  • fillchar 600k items

exponential slowdown.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information