We recently updated from JUCE 6.0.7 to JUCE 6.1.2. After the upgrade we noticed, that our TreeViews suddenly had very bad performance, when adding new nodes.
Things that took only a split second with JUCE 6.0.7, suddenly took several seconds in JUCE 6.1.2.
Our scenario is the following:
We have a TreeView, with one root node, which contains a LOT of children (approximately 1000 children). And the children are added to that that tree during run time (while the TreeView is already open and visible).
I debugged the problem and could see that
TreeViewItem::getItemHeight() was called a lot of times in JUCE 6.1.2. Much more often than in JUCE 6.0.7.
If you add 1000 nodes to such a TreeView in JUCE 6.1.2
TreeViewItem::getItemHeight() is called a whopping 502502 times! In contrast: doing the same in JUCE 6.0.7
TreeViewItem::getItemHeight() is called only 1002 times. In JUCE 6.0.7, the number of calls to
TreeViewItem::getItemHeight() correspond linearly to the number of added nodes. But in JUCE 6.1.2 its more like a square-law relation (I suspect it is node * (nodes+1) / 2).
I tracked it down to a change in
In JUCE 6.0.7
ownerView->itemsChanged(). But in JUCE 6.1.2 it calls
ownerView->updateVisibleItems() instead. The problem is, that
ownerView->updateVisibleItems() in turn calls
TreeView::updatePositions(), which iterates through all existing items and calls
TreeViewItem::getItemHeight() on them. So basically, adding only a single new item to the TreeView, makes the TreeView update all items in JUCE 6.1.2.
I have attached an example project, which you can use to test the behaviour (See TreeViewPerformanceTest.zip).
Here is how to reproduce:
- Run the test project.
- Click on the “Create Tree” button.
- Check what the label "calls to getItemHeight = " says. If you run it with JUCE 6.0.7, its going to show 1002 calls. But if you run it with JUCE 6.1.2 its going to show 502502 calls.
I assume that the changes to the TreeView have to do with the new Accessibility feature?
Would be great if the TreeView could get back the nice responsiveness it had in JUCE 6.0.7.
TreeViewPerformanceTest.zip (15.6 KB)