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

TreeItem.getItemCount() and TreeItem.getItem(int) have linear complexity on Linux #882

Open
basilevs opened this issue Nov 11, 2023 · 45 comments

Comments

@basilevs
Copy link
Contributor

basilevs commented Nov 11, 2023

The org.eclipse.swt.widgets.Tree is slow on Linux. In particular TreeItem.getItemCount() and TreeItem.getItem(int) have linear complexity (the time of execution is proportional to the number of children).

To Reproduce

Run JUnit test or following snippet:

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

public class TreeTest {

	private Shell shell = new Shell();
	{
		shell.setLayout(new FillLayout());
		shell.open();
	}


	public void getItemShouldHaveConstantTime() {
		for (int i = 0; i < 1000; i++) {
			measureGetItemTime(100); // warmup
		}
		double elapsed_10 = measureGetItemTime(10);
		double elapsed_100000 = measureGetItemTime(100000);
		double ratio = elapsed_100000 / elapsed_10;

		System.out.printf("Time for 10 elements: %f ns\nTime for 100000 elements: %f ns\nRatio: %f\n",elapsed_10, elapsed_100000, ratio);
	}

	private long measureGetItemTime(int count) {
		Tree tree = createTree();
		try {
			TreeItem subject = new TreeItem(tree, SWT.NONE);

			createChildren(subject, count);
			readAndDispatch();

			// warmup
			for (int i = 0; i < 1000; i++) {
				System.nanoTime();
				subject.getItem(count - 1);
			}

			long start = System.nanoTime();
			for (int i = 0; i < 10000; i++) {
				subject.getItem(count - 1);
			}
			long stop = System.nanoTime();
			long elapsed = stop-start;
			return elapsed;
		} finally {
			tree.dispose();
		}
	}

	private void createChildren(TreeItem subject, int count) {
		for (int i = 0; i < count; i++) {
			new TreeItem(subject, SWT.NONE);
		}
	}

	private Tree createTree() {
		Tree result = new Tree(shell, SWT.NONE);
		return result;
	}

	private void readAndDispatch() {
		for (int i = 0; i < 10; i++ ) {
			while(shell.getDisplay().readAndDispatch()) {}
		}
	}


}

This test wrapped in a product:
testporduct.zip (sources)
slowGetItem.linux.gtk.x86_64.zip slowGetItem.linux.gtk.aarch64.zip (built product)

Expected behavior
Access time should not depend on the number of items.

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Any GTK
  2. Any JRE

Version since
Was there always?

Workaround (or) Additional context
Initially reported in eclipse-platform/eclipse.platform.ui#649 Jface algorithms make navigation time proportional to a square of child count due to this problem.

Workaround: eclipse-platform/eclipse.platform.ui#810

GTK returns children count in O(N):

static gint
gtk_tree_store_iter_n_children (GtkTreeModel *tree_model,
				GtkTreeIter  *iter)
{
  GNode *node;
  gint i = 0;

  g_return_val_if_fail (iter == NULL || iter->user_data != NULL, 0);

  if (iter == NULL)
    node = G_NODE (GTK_TREE_STORE (tree_model)->priv->root)->children;
  else
    node = G_NODE (iter->user_data)->children;

  while (node)
    {
      i++;
      node = node->next;
    }

  return i;
}
@basilevs
Copy link
Contributor Author

I have not found a way to make TreeItem.getItemCount() without using this GTK API, but I have an idea of caching child count to help with JFace scenario, where child count does not change, but each child is accessed in sequence. Unfortunately, cache invalidation seems to quite complex with this approach.

basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 11, 2023
…pse-platform#882

On Linux these methods have linear complexity over child count, that
causes quadratic complexity for virtual tree navigation.
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 11, 2023
…pse-platform#882

On Linux these methods have linear complexity over child count, that
causes quadratic complexity for virtual tree navigation.
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 11, 2023
@laeubi
Copy link
Contributor

laeubi commented Nov 11, 2023

Just wondering, why do we need to query gtk at all? should not SWT/JFace be the one creating items and keep track of the count?

@SyntevoAlex
Copy link
Member

Indeed GTK gtk_tree_store_iter_n_children() iterates a list of items to count children:
https://github.com/GNOME/gtk/blob/3.24.38/gtk/gtktreestore.c#L766-L771

Note that on Windows, SWT caches number of items:

if (hItem == cachedFirstItem) {
if (cachedItemCount != -1) return cachedItemCount;
hFirstItem = cachedIndexItem;
count = cachedIndex;
}
while (hFirstItem != 0) {
hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hFirstItem);
count++;
}

@basilevs
Copy link
Contributor Author

basilevs commented Nov 11, 2023

Naive caching helps with childCount(), but getChilld(int) is ~ (3N), and when the fix is applied it stays O(N). See my PR comment.

@laeubi
Copy link
Contributor

laeubi commented Nov 12, 2023

@basilevs what I mean is that SWT itself is creating native items, so how could it be it does not knows (or could know) the number of items or the n-th item... so if the native implementation is to slow we probably should store an array of items on the java side that allows fast retrieval of childCount() and getChilld(int)

@laeubi
Copy link
Contributor

laeubi commented Nov 12, 2023

We don't need a whole copy of the model:

  1. Virtual only shows portions of the model that are visible
  2. One only needs to store the pointers to the natives to get a fast count/getX by not iterate the whole model

@basilevs
Copy link
Contributor Author

basilevs commented Nov 12, 2023

@laeubi as there no way to detect visible object going out of scope, it is impossible to clean the cache, which means we would store all the objects that had ever been shown indefinetly, which is not much better than whole model (indeed in context of Jface, this cache would have ALL items ever returned by content provider).
2. Storing pointers is effectively same as storing references to Java objects, given GTK implementation stores a cache of all(?) Java objects and has a way to transform pointers to references. In other words, given reference size, there is no benefit to store pointers instead of references - either way a cache of all items ever shown will form a copy of a model. (To clarify, I do not talk about model from JFace, I'm talking about model that native code holds, maybe I should use the term viewmodel).

@basilevs
Copy link
Contributor Author

We can avoid cache cleanup problem by only holding children of one item of interest, and repopulating it when interest shifts (Windows implementation does it for its caches).

basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 12, 2023
TreeItem.getItem(int) had linear complexity, full traversal had
quadratic complexity. To alleviate this, we cache the result.

Note: this only speeds up breadth-first traversal as cache operates on "item of interest" basis, dropping contents if another item is requested.
@basilevs
Copy link
Contributor Author

basilevs commented Nov 12, 2023

@laeubi I've implemented the cache and fixed the quadratic complexity of traversal, but the solution (in #883) stinks (is very slow on depth-first traversals). I'm still thinking about either making TreeItem volatile or implementing your suggestion of full model mirror. Both are disruptive.

@basilevs
Copy link
Contributor Author

I was wrong - efemeral Java TreeItems were never an option - strong references to them are held on all platforms.
The difference is : MacOS uses those strong references to keep track of parent-child relationship, while Linux and Windows create a convoluted system of identifiers to keep track of parents and children.

@laeubi
Copy link
Contributor

laeubi commented Nov 12, 2023

@basilevs as slow Tree performance is a major concern I think it would be great to improve it even if it might be disruptive, if you can prepare things we can merge as soon as master is open and have a full cycle to test so don't worry as long as all tests pass 👍

basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 12, 2023
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 12, 2023
datasets eclipse-platform#882

Test_org_eclipse_swt_widgets_Tree.test_getItemNoGrowth() was failing for
virtual trees.
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 12, 2023
@basilevs
Copy link
Contributor Author

basilevs commented Nov 13, 2023

I went with my dumb caching approach and it works for the scenario I'm interested in. It fails to actually make children tracking sensible, in particular, depth-first traversal is slow.

I suggest not to close this issue until someone volunteers to rework SWT GTK to actually make getItem() constant time.

basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 13, 2023
…-platform#882

As assertion now works with a time require for a single operation, we can't assume that non-constant operation will not fit in 100 ns window.
@iloveeclipse
Copy link
Member

@SyntevoAlex : any chance you could look at #883 & remark there regarding the "complete" solution?

basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 13, 2023
Tests have been modified to use time limits instead of fixed iteration
count. Now each test takes 7-14 seconds on Mac OS.
@SyntevoAlex
Copy link
Member

I could have a look on wednesday, if I don't forget.

basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 13, 2023
Any algorithm would be fast on a binary tree due to low count of items
in each node. We need a wide tree to break traversal tests.
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 13, 2023
Wide tree traversal shows performance 4 times worse than optimal on wide
trees.
@basilevs
Copy link
Contributor Author

basilevs commented Nov 14, 2023

The PR #883 is a failure. I've tested it on original testcase from eclipse-platform/eclipse.platform.ui#649 and the polynomial growth is 1.8 (approximation from three points) which for practical purposes is not different from the original 2.0. I give up for now. Sorry for all the noise!

@basilevs
Copy link
Contributor Author

basilevs commented Nov 18, 2023

An example of ID use case:

org.eclipse.swt.widgets.Tree.getFocusItem() {
	long [] path = new long [1];
	GTK.gtk_tree_view_get_cursor (handle, path, null);
	if (path [0] == 0) return null;
	TreeItem item = null;
	long iter = OS.g_malloc (GTK.GtkTreeIter_sizeof ());
	if (GTK.gtk_tree_model_get_iter (modelHandle, iter, path [0])) {
		int [] index = new int [1];
		GTK.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1);
		if (index [0] != -1) item = items [index [0]]; //TODO should we be creating this item when index is -1?
	}
	OS.g_free (iter);
	GTK.gtk_tree_path_free (path [0]);
	return item;
}

Here GTK returns an iterator and we need a TreeItem it corresponds to. As iterator is not a key, Tree has to use additional user data stored natively.
Same goes for event handler like org.eclipse.swt.widgets.Tree.cellDataProc(long, long, long, long, long) where items are addressed with iterators.

basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 19, 2023
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 19, 2023
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 29, 2023


The ID addressing system associating every TreeItem with an unique key
had been using GTK.gtk_tree_store_set() to persist a key in GTK model.
This operation has linear execution  time over model size.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 29, 2023
…tform#882

The ID system tracking association of every TreeItem with GTK model
entry had been using GTK.gtk_tree_store_set() to persist a key in GTK
model. This operation has linear execution  time over model size.

IDs were replaced with tree paths and strong references, which, if
implemented right, have logarithmic execution time on balanced trees and
constant execution time on wide trees.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 29, 2023
…tform#882

The ID system tracking association of every TreeItem with GTK model
entry had been using GTK.gtk_tree_store_set() to persist a key in GTK
model. This operation has linear execution  time over model size.

IDs were replaced with tree paths and strong references, which, if
implemented right, have logarithmic execution time on balanced trees and
constant execution time on wide trees.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 29, 2023
This run PerformanceTests in GitHub actions for pull requests labeled
"performance".

Note, that the event of labeling itself is not handled. This
implementation implies a contributor will have to push something to PR
after labeling to start tests.
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 29, 2023
…tform#882

The ID system tracking association of every TreeItem with GTK model
entry had been using GTK.gtk_tree_store_set() to persist a key in GTK
model. This operation has linear execution  time over model size.

IDs were replaced with tree paths and strong references, which, if
implemented right, have logarithmic execution time on balanced trees and
constant execution time on wide trees.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 30, 2023
…tform#882

The ID system tracking association of every TreeItem with GTK model
entry had been using GTK.gtk_tree_store_set() to persist a key in GTK
model. This operation has linear execution  time over model size.

IDs were replaced with tree paths and strong references, which, if
implemented right, have logarithmic execution time on balanced trees and
constant execution time on wide trees.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Dec 3, 2023
…ipse-platform#882

TreeItem and Tree have been checking indexes for bounds during indexed
access and traversal. Such checks are slow as node size computation is
an O(N) operation.

As Tree already does iteration when retrieving a TreeItem by its index,
and such iteration detects out-of-bounds problems, preliminary model
bounds check is redundant. Also, bounds check is avoidable during
iteration over a node - instead of an index, GTK iterator applies
directly.

Performance improvement proved 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%)
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Dec 3, 2023
This run PerformanceTests in GitHub actions for pull requests labeled
"performance".

Note, that the event of labeling itself is not handled. This
implementation implies a contributor will have to push something to PR
after labeling to start tests.
laeubi pushed a commit that referenced this issue Dec 3, 2023
This run PerformanceTests in GitHub actions for pull requests labeled
"performance".

Note, that the event of labeling itself is not handled. This
implementation implies a contributor will have to push something to PR
after labeling to start tests.
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Dec 3, 2023
…ipse-platform#882

TreeItem and Tree have been checking indexes for bounds during indexed
access and traversal. Such checks are slow as node size computation is
an O(N) operation.

As Tree already does iteration when retrieving a TreeItem by its index,
and such iteration detects out-of-bounds problems, preliminary model
bounds check is redundant. Also, bounds check is avoidable during
iteration over a node - instead of an index, GTK iterator applies
directly.

Performance improvement proved 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%)
SyntevoAlex pushed a commit that referenced this issue Jan 7, 2024
TreeItem and Tree have been checking indexes for bounds during indexed
access and traversal. Such checks are slow as node size computation is
an O(N) operation.

As Tree already does iteration when retrieving a TreeItem by its index,
and such iteration detects out-of-bounds problems, preliminary model
bounds check is redundant. Also, bounds check is avoidable during
iteration over a node - instead of an index, GTK iterator applies
directly.

Performance improvement proved 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%)
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Jan 22, 2024
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Jan 22, 2024
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Jan 23, 2024
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Jan 27, 2024
…tform#882

The ID system tracking association of every TreeItem with GTK model
entry had been using GTK.gtk_tree_store_set() to persist a key in GTK
model. This operation has linear execution  time over model size.

IDs were replaced with tree paths and strong references, which, if
implemented right, have logarithmic execution time on balanced trees and
constant execution time on wide trees.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Jan 27, 2024
…tform#882

The ID system tracking association of every TreeItem with GTK model
entry had been using GTK.gtk_tree_store_set() to persist a key in GTK
model. This operation has linear execution  time over model size.

IDs were replaced with tree paths and strong references, which, if
implemented right, have logarithmic execution time on balanced trees and
constant execution time on wide trees.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Jan 27, 2024
…tform#882

The ID system tracking association of every TreeItem with GTK model
entry had been using GTK.gtk_tree_store_set() to persist a key in GTK
model. This operation has linear execution  time over model size.

IDs were replaced with tree paths and strong references, which, if
implemented right, have logarithmic execution time on balanced trees and
constant execution time on wide trees.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Jan 27, 2024
…tform#882

The ID system tracking association of every TreeItem with GTK model
entry had been using GTK.gtk_tree_store_set() to persist a key in GTK
model. This operation has linear execution  time over model size.

IDs were replaced with tree paths and strong references, which, if
implemented right, have logarithmic execution time on balanced trees and
constant execution time on wide trees.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
jukzi pushed a commit to basilevs/eclipse.platform.swt that referenced this issue Mar 8, 2024
…tform#882

The ID system tracking association of every TreeItem with GTK model
entry had been using GTK.gtk_tree_store_set() to persist a key in GTK
model. This operation has linear execution  time over model size.

IDs were replaced with tree paths and strong references, which, if
implemented right, have logarithmic execution time on balanced trees and
constant execution time on wide trees.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Mar 8, 2024
Optional performance tests rely on prebuilt SWT components to be available.
`mvn install` is essential for this.
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Mar 9, 2024
Optional performance tests rely on prebuilt SWT components to be available.
`mvn install` is essential for this.
HannesWell pushed a commit that referenced this issue Mar 12, 2024
Optional performance tests rely on prebuilt SWT components to be available.
`mvn install` is essential for this.
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Mar 13, 2024
…tform#882

The ID system tracking association of every TreeItem with GTK model
entry had been using GTK.gtk_tree_store_set() to persist a key in GTK
model. This operation has linear execution  time over model size.

IDs were replaced with tree paths and strong references, which, if
implemented right, have logarithmic execution time on balanced trees and
constant execution time on wide trees.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Mar 14, 2024
…tform#882

The ID system tracking association of every TreeItem with GTK model
entry had been using GTK.gtk_tree_store_set() to persist a key in GTK
model. This operation has linear execution  time over model size.

IDs were replaced with tree paths and strong references, which, if
implemented right, have logarithmic execution time on balanced trees and
constant execution time on wide trees.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
@basilevs
Copy link
Contributor Author

basilevs commented Jul 4, 2024

Current status: #918 is ready for review.

akurtakov pushed a commit to basilevs/eclipse.platform.swt that referenced this issue Oct 4, 2024
…tform#882

The ID system tracking association of every TreeItem with GTK model
entry had been using GTK.gtk_tree_store_set() to persist a key in GTK
model. This operation has linear execution  time over model size.

IDs were replaced with tree paths and strong references, which, if
implemented right, have logarithmic execution time on balanced trees and
constant execution time on wide trees.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
akurtakov pushed a commit to basilevs/eclipse.platform.swt that referenced this issue Oct 9, 2024
…tform#882

The ID system tracking association of every TreeItem with GTK model
entry had been using GTK.gtk_tree_store_set() to persist a key in GTK
model. This operation has linear execution  time over model size.

IDs were replaced with tree paths and strong references, which, if
implemented right, have logarithmic execution time on balanced trees and
constant execution time on wide trees.

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:  141_061_117ns -> 4_369_889ns
100_000 elements: 10_761_449_641ns -> 181_898_611ns (-98%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants