Performance issue on Clear of OrderedDictionary

Issue #282 resolved
Mark Ford created an issue

There appears to be a performance issue when clearing an Ordered Dictionary. The steps to confirm are :

  Tik := GetTickCount;
  DictOrdered := TCollections.CreateOrderedDictionary<string, string>;
  for i := 0 to Length(WordArrayShuffled) - 1 do
    DictOrdered.Add(WordArraySorted[i], WordArrayShuffled[i]);
  Memo1.Lines.Add('Filling Ordered Dictionary: ' + IntToStr(GetTickCount - Tik));
  Tik := GetTickCount;
  DictOrdered.Clear;
  Memo1.Lines.Add('Clearing Ordered Dictionary: ' + IntToStr(GetTickCount - Tik));

The WordArray used to fill the dictionary is 100,000 English words. Filling the ordered dictionary takes 63milliseconds but clearing it takes 41 seconds.

Comments (8)

  1. Stefan Glienke repo owner
    • changed status to open

    Looks like it's missing a specific Clear override to clear the keylist first. Currently it will look for all 100000 keys in the keylist and remove them each.

  2. Log in to comment