I am optimizing a part of a Delphi application, where the list of objects is often filtered using different criteria. The objects are stored in the TObjectList structure, and each filter is usually used to select the entire collection very small Percentage of (e.g. 1%). The total number of objects can be in the range of 100k, and the main set will not change during the calculation. Although the filter is only applied to a few attributes, the list cannot be sorted to optimize all possible criteria.
I am looking for suggestions on how to organize objects (data structures) or algorithms that can be used to solve this problem. Thank you!
Filter example:
((Object.A between 5 and 15) AND
(Object.B <20) AND
(Object.C(AParam)> 0)) OR
(Object.IsRoot(...))
< div class="answer"> Idea #1
Run your code in the analyzer. Find out if there is any slowness.
Idea #2
You can take advantage of the caching effect by storing objects in memory in order. (I assume you go through your list from beginning to end.)
One way may be to use an array of records. Not a list of objects. If this is possible in your case. Remember that records in Delphi 2006 can have methods (but not virtual methods).
Another idea might be to write your own class Allocator. I have never tried it, but here’s an article I found. Maybe try to use pointers instead of TObjectList for objects.
I’m optimizing part of a Delphi application , Where the object list is often filtered using different criteria. The objects are stored in the TObjectList structure, and each filter is usually used to select a very small percentage of the entire collection (for example, 1%). The total number of objects can be in the range of 100k, and the calculation The main collection will not change during the period. Although the filter is only applied to a few attributes, it is not possible to sort the list to optimize all possible criteria.
I am looking for information on how to organize the objects (data structure) Or suggestions for algorithms that can be used to solve 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 the analyzer. Find out if there is any slowness.
Idea #2
You can store the objects in order Take advantage of the cache effect in memory. (I assume you go through your list from beginning to end.)
One way might be to use an array of records instead of a list of objects. If in your case this is Possible. Remember that records in Delphi 2006 can have methods (but not virtual methods).
Another idea might be to write your own class allocator. I have never tried it, but here’s an article I found. Maybe try to use pointers instead of TObjectList for objects.