Bug 133176 - Performance degradation in Control.forceFocus()
Summary: Performance degradation in Control.forceFocus()
Status: RESOLVED INVALID
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2006-03-24 12:37 EST by Dani Megert CLA
Modified: 2006-04-19 11:22 EDT (History)
2 users (show)

See Also:


Attachments
Performance data (350.03 KB, application/octet-stream)
2006-03-24 12:43 EST, Dani Megert CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2006-03-24 12:37:31 EST
I20060314-0800.

Found this while tracking down degradation of "Activate 30 Java Editors" tests. The attached comparisons and hot spot listings show that with same amount of invocations Control.forceFocus() became considerably slower and let it appear near the top of the 3.2 hot spots.
Comment 1 Dani Megert CLA 2006-03-24 12:43:13 EST
Created attachment 36895 [details]
Performance data
Comment 2 Steve Northover CLA 2006-03-29 14:08:28 EST
Here is a simple benchmark:

import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class PR_133176 {
	public static void main(String[] args) {
		final Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		Tree tree = new Tree(shell, SWT.BORDER | SWT.CHECK);
		for (int i=0; i<270; i++) {
			TreeItem item = new TreeItem (tree, SWT.NONE);
			item.setText ("Item " + i);
		}
		Tree tree2 = new Tree(shell, SWT.BORDER | SWT.CHECK);
		for (int i=0; i<270; i++) {
			TreeItem item = new TreeItem (tree2, SWT.NONE);
			item.setText ("Item " + i);
		}
		shell.open();
		long t0 = System.currentTimeMillis ();
		for (int i=0; i<100000; i++) {
			if (i % 2 == 0) {
				tree.forceFocus ();
			} else {
				tree2.forceFocus ();
			}
		}
		long t1 = System.currentTimeMillis ();
		System.out.println ("Time: " + (t1 - t0));
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}
}
Comment 3 Steve Northover CLA 2006-03-29 14:10:09 EST
Running the simple benchmark on 3.1 and 3.2 M6 (well, almost M6) gives the same results.  Obviously, the benchmark is too simple and is not capturing what is happening.

Are you able to recreate the slowdown every time?
Comment 4 Dani Megert CLA 2006-03-29 15:17:20 EST
>Are you able to recreate the slowdown every time?
I made 4 measurements with different approaches and they showed the diff, but the scenario was more complex. The interesting part is that the invocation count was the same. I can repeat it tomorrow again but you might do the same using my scenario.

My benchmark was to
1. install buildX
2. start fresh workspace
3. load jdt.text.tests + required plug-ins from repository
4. instrumented the ActivateEditorTest.measureActivateEditor so that it 
   waits after the warm up phase (==> manually start profiler) and after the 
   test (==>  manually stop profiler)
5. started ActivateJavaEditorTest
6. started profiler when the test waited
7. stopped the profiler when the test waited

The 'wait' was simply done by showing a dialog.
Comment 5 Steve Northover CLA 2006-03-29 15:24:26 EST
I would claim that focus was bouncing around but the number of invokations is the same.  Let me know how you get on.
Comment 6 Dani Megert CLA 2006-04-19 10:41:59 EDT
I found out that there was a driver problem on my machine. I reran the tests after fixing the driver and the forceFocus() no longer differed.

Sorry for the noise.
Comment 7 Steve Northover CLA 2006-04-19 11:22:22 EDT
No problem!