First of all, I answer my Q / A question, so I don’t have to answer anyone for this. This is what I learned, and many can use it.
I have a tree structure made up of many different nodes. Each node has an object behind it in the Data property, and objects refer to different levels of the hierarchy from one main list of objects, which is quite large (many thousands of elements). One node represents a specific property of this main listed object, where the tree allows the user to select a node to view those elements that belong to this particular selected category.
When a tree fills up, it becomes extremely time-consuming (in some cases 2 minutes), because each node must iterate over each element in this large list and find every element in this list that matches any given node. Therefore, if there are 500 nodes in this tree, then it repeats this large list 500 times. The total number of hierarchy levels is 3 levels. When loading the second and third levels, a performance throttle occurs, but the first level is simple and fast.
Now there are no options for increasing the repetition performance through this list hundreds of times. I am wondering if there are any known tricks to improve the performance of populating a tree view?
Here's how it works at the moment:
var X: Integer; N: TTreeNode; O: TMyObject; begin for X := 0 to MyObjectList.Count - 1 do begin O:= TMyObject(MyObjectList[X]); //Object which Node represents N:= TreeView.Items.AddChild(nil, O.Caption); N.Data:= O; LoadNextLevel(N); //Populates child nodes by iterating through master list again end; end;
And a similar method for each additional level.
PS - The first level of the hierarchy is populated from a separate own list (about 50 objects), while the second and third levels are populated from the properties of these thousands of objects in the main list. That's why the first level loads fast, and the rest is slower.
performance delphi large-data treeview
Jerry dodge
source share