My application makes heavy use of TList, so I was wondering if there are any alternative implementations that are faster or optimized for particular use case.
I know
One of the biggest bottleneck I know about TList is the Delete/Extract on large list. Removing item[0] is a lot slower than removing Item[Count-1] because of the memory move that follows it.
For exemple, on a list containing 65536 elements:
while list.Count > 0 do List.Delete(0) //Takes 2 mins to complete
for I := List.Count-1 downto 0 do List.Delete(I) //Takes less than 1 sec
So if you have a TList with millions of elements, deleting a low index item can be expensive performance-wise. Also, consider that having a list that isn't sorted makes it very slow to find an element in it. IndexOf is very slow on large list. You might want to consider keeping the list sorted.
Also, considering your item count can be pretty large, you might want to consider using a List of TList to store your elements, which will help reduce the Delete/Extract overhead I already mentioned.