Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GTK] Optimize TreeItem.getItem(int) by caching TreeItem.getItems() #882 #908

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

basilevs
Copy link
Contributor

@basilevs basilevs commented Nov 27, 2023

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 when TreeItem.getItems() is called before TreeItem.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:
Screenshot 2023-11-26 at 21 22 34
Profile after the change:
Screenshot 2023-11-27 at 14 09 00

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

Testing asymptotic execution times for operations over large trees.
iterator eclipse-platform#882

This change eliminates a single hotspot. The overall complexity of
tree building and element reveal is still quadratic.

Performance improvement is proven by running
org.eclipse.swt.tests.junit.performance.Test_org_eclipse_swt_widgets_Tree.jfaceReveal()

In test jfaceReveal[Shape: STAR, virtual: true]:
10_000 elements: 620_682_717ns -> 501_378_662ns
100_000 elements: 62_804_214_489ns -> 52_781_899_817ns (-16%)
…-platform#882

As we already do iteration of O(N) complexity, and it detects
out-of-bounds problems, eliminate redundant model size check computed in
O(N).

Performance improvement is proven by running
org.eclipse.swt.tests.junit.performance.Test_org_eclipse_swt_widgets_Tree.jfaceReveal()

In test jfaceReveal[Shape: STAR, virtual: true]:
10_000 elements:  501_378_662ns -> 218_583_468ns
100_000 elements: 52_781_899_817ns -> 20_872_245_796ns (-60%)
…clipse-platform#882

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
@akurtakov
Copy link
Member

What is the status here ? I see #918 and #904 related. Would you please clarify and close unneeded ones?

@basilevs
Copy link
Contributor Author

basilevs commented Jan 6, 2024

This is needed for review of #918 and subsequent related PRs. Work on #918 is blocked by review of #904, my only non-draft PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants