Bug 60247 JUnit compare dialog memory usage
Eclipse build id 200403261517 (3.0M8 I think) on Windows 2000SP4, JDK 1.4.2_04. Using vmarg parameters: -Xms64M -Xmx640M (1,7Ghz Celeron with 512MB physical RAM) I noticed that in some cases the compare dialog in the junit view shows after a large pause and use a lot of memory. I try to create a reproducable test case: public class JUnitCompareTest extends TestCase { private String getString1() { return "123456789012345678901234567890"; } private String getString2() { return "098765432109876543210987654321"; } public void testCompare1() throws Exception { assertEquals(getString1(), getString2()); } public void testCompare50() throws Exception { StringBuffer buf = new StringBuffer(); for (int i = 0; i < 50; i++) { buf.append(getString1()); buf.append("\r\n"); } String s1 = buf.toString(); buf = new StringBuffer(); for (int i = 0; i < 50; i++) { buf.append(getString2()); buf.append("\r\n"); } String s2 = buf.toString(); assertEquals(s1, s2); } public void testCompare100() throws Exception { StringBuffer buf = new StringBuffer(); for (int i = 0; i < 100; i++) { buf.append(getString1()); buf.append("\r\n"); } String s1 = buf.toString(); buf = new StringBuffer(); for (int i = 0; i < 100; i++) { buf.append(getString2()); buf.append("\r\n"); } String s2 = buf.toString(); assertEquals(s1, s2); } public void testCompare150() throws Exception { StringBuffer buf = new StringBuffer(); for (int i = 0; i < 150; i++) { buf.append(getString1()); buf.append("\r\n"); } String s1 = buf.toString(); buf = new StringBuffer(); for (int i = 0; i < 150; i++) { buf.append(getString2()); buf.append("\r\n"); } String s2 = buf.toString(); assertEquals(s1, s2); } } Using this test case in the above mentioned configuration I got the following data (data is from "VM size" in the Windows Task Manager which is roughly correct but I think it illustrates the problem well). The first value is the VM size before showing the compare dialog, the second value is the VM size after the dialog displays, and the third value is the 'display time'. Get popup for testCompare1(): 158912 -> 159408 ( < 1s) Get popup for testCompare50(): 159376 -> 202908 ( ~ 3s) Get popup for testCompare100(): 173352 -> 440496 ( ~ 10s) Get popup for testCompare150(): 156476 -> 731304 (kill Eclipse after 5 minute) I suspect the problem is with there are many differences to create (because a 150-line difference where there will be 2 diff/line shows up < 1s). It would be nice to have an option to not creates these diffs only shows the text with only the colors for indicating the differences. Regards, Csaba
org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/CompareResultDialog.java
Control previewer= createPreviewer(pane);
		pane.setContent(previewer);
		GridData gd= new GridData(GridData.FILL_BOTH);
		previewer.setLayoutData(gd);
		applyDialogFont(parent);
		return composite;
	}
	
	private Control createPreviewer(Composite parent) {
	    final CompareConfiguration compareConfiguration= new CompareConfiguration();
	    compareConfiguration.setLeftLabel(JUnitMessages.getString("CompareResultDialog.expectedLabel")); 
	    compareConfiguration.setLeftEditable(false);
	    compareConfiguration.setRightLabel(JUnitMessages.getString("CompareResultDialog.actualLabel"));	 
	    compareConfiguration.setRightEditable(false);
	    compareConfiguration.setProperty(CompareConfiguration.IGNORE_WHITESPACE, new Boolean(false));
	    fViewer= new CompareResultMergeViewer(parent, SWT.NONE, compareConfiguration);
	    fViewer.setInput(new DiffNode( 
        new CompareElement(fExpected), 
        new CompareElement(fActual)));
	    Control control= fViewer.getControl();
	    control.addDisposeListener(new DisposeListener() {
	        public void widgetDisposed(DisposeEvent e) {
	            if (compareConfiguration != null)
	                compareConfiguration.dispose();
	        }
	    });
	    return  control;
	}	
}