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

Opening big Trees is slow #123

Open
2 tasks
fedejeanne opened this issue Sep 23, 2024 · 2 comments
Open
2 tasks

Opening big Trees is slow #123

fedejeanne opened this issue Sep 23, 2024 · 2 comments
Assignees
Labels
Performance A Request for a Performance Improvement Platform UI Issue for Platform UI Student An Issue to be Addressed By a Student SWT Issue for SWT

Comments

@fedejeanne
Copy link

fedejeanne commented Sep 23, 2024

Problem

Related to #2

Opening big/deep Trees can be quite slow e.g. when showing deep hierarchies the Hierarchy View. For example when opening the hierarchy of MECU (meta-model class), it can take some minutes to do it and the UI is frozen.

Goal

  • No UI freeze when opening big trees (hierarchies)

Steps

  • Reproduce the problem and provide a Visual-VM sample that shows where the problem lies
  • Evaluate possible approaches to deal with the issue e.g. doing some processing outside of the UI thread or making the whole thing cancelable (like when one opens the call hierarchy of a method)

Hint

  • There are hints of it in the SWT Book by Northover and Wilson (Chapter 9, section "Using SWT.Expand to Fill a Tree Lazily").
  • Look at the method org.eclipse.jface.viewers.AbstractTreeViewer.internalConditionalExpandToLevel(Widget, int, Function<Widget, Boolean>), there's currently a hint in the code that points to that but sadly a better implementation can not be provided because it wouldn't work on Linux:
Method
	private void internalConditionalExpandToLevel(Widget widget, int level,
			Function<Widget, Boolean> shouldChildrenExpand) {
		if (level == ALL_LEVELS || level > 0) {
			Object data = widget.getData();
			if (widget instanceof Item it && data != null && !isExpandable(it, null, data)) {
				return;
			}
			createChildren(widget, false);
			// XXX for performance widget should be expanded after expanding children:
			if (widget instanceof Item it) {
				setExpanded(it, true);
			}
			if (level == ALL_LEVELS || level > 1) {
				Item[] children = getChildren(widget);
				if (children != null) {
					int newLevel = (level == ALL_LEVELS ? ALL_LEVELS
							: level - 1);
					for (Item element : children) {
						if (shouldChildrenExpand.apply(widget).booleanValue()) {
							internalConditionalExpandToLevel(element, newLevel, shouldChildrenExpand);
						}
					}
				}
			}
			// XXX expanding here fails on linux
		}
	}

You can change the implementation (move the if (widget instanceof Item it) {...} to be executed after the other if) and use the test snippet below to see how the change breaks the implementation on Linux

Test snippet
public class Main {

	static interface I1 {}
	static interface I2 extends I1 {}
	static interface I3 extends I2 {}
	static interface I4 extends I3 {}
	static interface I5 extends I4 {}
	
	static class C2 implements I2 {}
	static class C3 implements I3 {}
}

You'll see for example that showing the hierarchy of I3 produces different results.

This is with the current (slow) implementation:

Image

This is with the modified (fast) implementation, which wouldn't work properly on Linux:

Image

@fedejeanne fedejeanne added Platform UI Issue for Platform UI SWT Issue for SWT Performance A Request for a Performance Improvement Student An Issue to be Addressed By a Student labels Sep 23, 2024
@jannisCode jannisCode self-assigned this Oct 11, 2024
@christianstaib christianstaib self-assigned this Oct 25, 2024
@jannisCode
Copy link

I think I got a solution for the Problem. In the class TypeHierarchyViewPart.java and Method updateViewers() you have to put the updateHierarchyViewer(true) after updateMethodViewer(root) because otherwise it updates the wrong thing.
Then expanding the children later should not be a Problem anymore (I tested it on linux and windows)

@jannisCode
Copy link

I need help for testing the changes. I tried using VisualVM, but it didn´t work the way I wanted, because I can´t see any differences between the old and new implementation.

Also I tried measuring the time t takes to run the method, but I didn´t really see any difference between the old and new implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance A Request for a Performance Improvement Platform UI Issue for Platform UI Student An Issue to be Addressed By a Student SWT Issue for SWT
Projects
Status: 🏗 In Work: Short
Development

No branches or pull requests

3 participants