Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLeo Ufimtsev2018-05-29 17:06:32 +0000
committerLeo Ufimtsev2018-05-29 19:09:44 +0000
commit65ddc8a5374963e50f794bf6b3b36d84dd19105d (patch)
tree24fbb94106527782111720cd6f129981140c2578 /tests
parent2bd7cc57d6f8db85984adca7abc84236618f0b2d (diff)
downloadeclipse.platform.swt-65ddc8a5374963e50f794bf6b3b36d84dd19105d.tar.gz
eclipse.platform.swt-65ddc8a5374963e50f794bf6b3b36d84dd19105d.tar.xz
eclipse.platform.swt-65ddc8a5374963e50f794bf6b3b36d84dd19105d.zip
Bug 489640 [GTK3] setting a lot of items to combobox is extremely slow
(Bug fix). Setting wrap causes O(n^2) performance regression because after every insert the drop-down list size is re-computed. Solution: 1) Turn off wrap during insert (to fix bulk insert, e.g setItems(...)) 2) Delay enabling (so that multiple single-insert calls [e.g add(.)] are not delayed if called in a loop. Tests: - Attached snippets: Before fix: Gtk3: 1000ms After fix: Gtk3: 10ms (event faster than gtk2's 23ms). - Child eclipse works well. - All SWT jUnits pass. - Combo box looks same as before. Patchset 4: - Implemented similar logic for removing items to fix performance. Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=4896403 Change-Id: Ibf14b35712277e068bc719d073a482ab5c04fb7f Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug489640_ComboPerformanceTest.java96
1 files changed, 68 insertions, 28 deletions
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug489640_ComboPerformanceTest.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug489640_ComboPerformanceTest.java
index 4d5b3a6d76..6d09b91656 100644
--- a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug489640_ComboPerformanceTest.java
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug489640_ComboPerformanceTest.java
@@ -11,44 +11,39 @@
package org.eclipse.swt.tests.gtk.snippets;
-import java.nio.charset.*;
-import java.util.*;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
-import org.eclipse.swt.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+/*
+ * Title: Adding items in combo box grows at O(n^2).
+ * how to run: Run on Gtk2/3 with/without fix to observe different run times.
+ * Gtk2, +-20 ms
+ * Gtk3, +- 1000ms
+ * Gtk3 with fix: += 10ms.
+ *
+ * Once snippet launched, try 'refill' button, which tests time it takes to remove entries.
+ *
+ */
public class Bug489640_ComboPerformanceTest {
public static void main(String[] args) {
- final Map<String, Charset> charSets = Charset.availableCharsets();
- final List<String> encodings = new ArrayList<>(charSets.keySet());
- Collections.sort(encodings);
-
final Display display = new Display();
-
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
- final Combo combo = new Combo(shell, SWT.BORDER | SWT.READ_ONLY);
- combo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
-
- final Button button = new Button(shell, SWT.PUSH);
- button.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
- button.setText("Fill Combo");
- button.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- final String[] items = encodings.toArray(new String[encodings.size()]);
- System.out.println("Setting widget.combo with " + items.length + " items");
- final long start = System.currentTimeMillis();
- combo.setItems(items);
- final long end = System.currentTimeMillis();
- System.out.println("took " + (end - start) + " ms.");
- combo.select(0);
- }
- });
+ test_setItems(shell);
+ test_addItems(shell);
shell.setSize(400, 200);
shell.open();
@@ -61,4 +56,49 @@ public class Bug489640_ComboPerformanceTest {
display.dispose();
}
+
+ private static void test_addItems(final Shell shell) {
+ final Combo combo = new Combo(shell, SWT.BORDER | SWT.READ_ONLY);
+ combo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+
+ final long start = System.currentTimeMillis();
+ int count = 200;
+ final String[] items = new String[count];
+ for (int i = 0; i < count; i++) {
+ combo.add("item " + i); // <<< via add.
+ }
+ System.out.println("Combo.add(..) took " + (System.currentTimeMillis() - start) + " ms. (1000ms = bad. 20ms = good.)");
+ combo.select(0);
+ }
+
+ private static void test_setItems(final Shell shell) {
+ final Combo combo = new Combo(shell, SWT.BORDER | SWT.READ_ONLY);
+ combo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+
+ int count = 200;
+ final String[] items = new String[count];
+ for (int i = 0; i < count; i++) {
+ items[i] = new String("item " + i);
+ }
+ final long start = System.currentTimeMillis();
+ combo.setItems(items);
+ System.out.println("Combo.setItems(.) took " + (System.currentTimeMillis() - start) + " ms. (1000ms = bad. 20ms = good.)");
+ combo.select(0);
+
+ final Button button = new Button(shell, SWT.PUSH);
+ button.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
+ button.setText("Refill Combo at runtime");
+ button.addListener(SWT.Selection, event -> {
+ final Map<String, Charset> charSets = Charset.availableCharsets();
+ final List<String> encodings = new ArrayList<>(charSets.keySet());
+ Collections.sort(encodings);
+ final String[] items1 = encodings.toArray(new String[encodings.size()]);
+ System.out.println("Setting widget.combo with " + items1.length + " items");
+ final long start1 = System.currentTimeMillis();
+ combo.setItems(items1);
+ final long end = System.currentTimeMillis();
+ System.out.println("took " + (end - start1) + " ms.");
+ combo.select(0);
+ });
+ }
}

Back to the top