I am optimizing a part of a Delphi application where lists of objects are frequently filtered using different criteria. The objects are kept in TObjectList structures and it is common to select a very small percentage (ex. 1%) of the entire set with each filter. The total number of objects can be in the 100k range and during computations the main set doesn’t change. Although the filters are applied for only a few properties, the lists cannot be sorted in such a way that would optimize all the possible criteria.
I am looking for suggestions on how to organize the objects (data structures) or an algorithm that can be used to approach this problem. Thank you!
Filter example:
((Object.A between 5 and 15) AND
(Object.B < 20) AND
(Object.C(AParam) > 0)) OR
(Object.IsRoot(...))
Idea #1
Run your code in a profiler. Find out if there are any slow spots.
Idea #2
Possibly you could take advantage of cache effects by storing your objects sequentially in memory. (I’m assuming you are walking your list sequentially from beginning to end.)
One way to do it might be to use an array of records instead of a list of objects. If that’s possible in your case. Remember that records in Delphi 2006 can have methods (but not virtual ones).
Another idea might be to write your own class allocator. I’ve never tried that, but here’s an article I found. Maybe try walking the objects using a pointer instead of using the TObjectList.