[GTK] Optimize TreeItem.getItem(int) by caching TreeItem.getItems() #882 #908
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
DO NOT MERGE - this is a demonstration, not an actual solution. See below.
This is a follow up to #903 and #904.
This PR eliminates explicit iterations over
Tree
from execution profile whenTreeItem.getItems()
is called beforeTreeItem.getItem(int)
. This is the case for JFace lazy TreeViewer.Performance improvement is proven by running relevant tests from
org.eclipse.swt.tests.junit.performance.Test_org_eclipse_swt_widgets_Tree:
In test jfaceReveal[Shape: STAR, virtual: true]:
10_000 elements: 218_583_468ns -> 141_061_117ns
100_000 elements: 20_872_245_796ns -> 10_761_449_641ns (-48%)
In test dispose[Shape: STAR, virtual: true]:
10_000 elements: 5_637_088ns -> 6_222_363ns
100_000 elements: 62_422_153ns -> 56_442_156ns
Profile before the change:
Profile after the change:
The solution here is ideologically incorrect, as it targets a particular way of tree traversal, specific to JFAce lazy tree. However, a more general and self-consistent approach, that moves ownership of a TreeItem from a Tree to a parent item, prototyped in master...basilevs:eclipse.platform.swt:issue_882_gtk_direct_access is a much larger change. I suggest not to merge this PR and just use it as a starting point for discussion on removal of ID system from SWT GTK Tree.
The removal itself is done in #918