View | Details | Raw Unified | Return to bug 135906
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java (+50 lines)
Lines 760-765 Link Here
760
	}
760
	}
761
}
761
}
762
762
763
/*
764
 * Ensures that the performance of reconcile on a CU with lots of duplicates is acceptable.
765
 * (regression test for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=135906 )
766
 */
767
public void testReconcileDuplicates() throws JavaModelException {
768
	tagAsSummary("Reconcile editor change on file with lots of duplicates", false); // do NOT put in fingerprint
769
	
770
	// build big file contents
771
	StringBuffer contents = new StringBuffer();
772
	contents.append("public class CUWithDuplicates {\n");
773
	int fooIndex = 0;
774
	while (fooIndex < 2000) { // add 2000 duplicate methods
775
		contents.append("  void foo() {}\n");
776
		contents.append(fooIndex++);
777
	}
778
	contents.append("} //"); // ensure it ends with a line comment that is edited below
779
	
780
	ICompilationUnit workingCopy = null;
781
	try {
782
		// Setup
783
		workingCopy = (ICompilationUnit) JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/BigProject/src/CUWithDuplicates.java")));
784
		workingCopy.becomeWorkingCopy(null);
785
		
786
		// Warm up
787
		int warmup = WARMUP_COUNT / 10;
788
		for (int i=0; i<warmup; i++) {
789
			workingCopy.getBuffer().setContents(contents.append('a').toString());
790
			workingCopy.reconcile(AST.JLS3, false/*no pb detection*/, null/*no owner*/, null/*no progress*/);
791
		}
792
	
793
		// Measures
794
		resetCounters();
795
		for (int i=0; i<MEASURES_COUNT; i++) {
796
			workingCopy.getBuffer().setContents(contents.append('a').toString());
797
			runGc();
798
			startMeasuring();
799
			workingCopy.reconcile(AST.JLS3, false/*no pb detection*/, null/*no owner*/, null/*no progress*/);
800
			stopMeasuring();
801
		}
802
		
803
		// Commit
804
		commitMeasurements();
805
		assertPerformance();		
806
		
807
	} finally {
808
		if (workingCopy != null)
809
			workingCopy.discardWorkingCopy();
810
	}
811
}
812
763
/**
813
/**
764
 * Ensures that the reconciler does nothing when the source
814
 * Ensures that the reconciler does nothing when the source
765
 * to reconcile with is the same as the current contents.
815
 * to reconcile with is the same as the current contents.
(-)model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java (-3 / +14 lines)
Lines 33-38 Link Here
33
import org.eclipse.jdt.internal.compiler.parser.Parser;
33
import org.eclipse.jdt.internal.compiler.parser.Parser;
34
import org.eclipse.jdt.internal.compiler.parser.RecoveryScanner;
34
import org.eclipse.jdt.internal.compiler.parser.RecoveryScanner;
35
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
35
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
36
import org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt;
36
import org.eclipse.jdt.internal.core.util.ReferenceInfoAdapter;
37
import org.eclipse.jdt.internal.core.util.ReferenceInfoAdapter;
37
import org.eclipse.jdt.internal.core.util.Util;
38
import org.eclipse.jdt.internal.core.util.Util;
38
39
Lines 63-68 Link Here
63
	 * info objects.
64
	 * info objects.
64
	 */
65
	 */
65
	protected Map newElements;
66
	protected Map newElements;
67
	
68
	/*
69
	 * A table from a handle (with occurenceCount == 1) to the current occurence count for this handle
70
	 */
71
	private HashtableOfObjectToInt occurenceCounts;
66
72
67
	/**
73
	/**
68
	 * Stack of parent scope info objects. The info on the
74
	 * Stack of parent scope info objects. The info on the
Lines 115-120 Link Here
115
	this.unit = unit;
121
	this.unit = unit;
116
	this.unitInfo = unitInfo;
122
	this.unitInfo = unitInfo;
117
	this.newElements = newElements;
123
	this.newElements = newElements;
124
	this.occurenceCounts = new HashtableOfObjectToInt();
118
} 
125
} 
119
/**
126
/**
120
 * @see ISourceElementRequestor
127
 * @see ISourceElementRequestor
Lines 618-628 Link Here
618
}
625
}
619
/**
626
/**
620
 * Resolves duplicate handles by incrementing the occurrence count
627
 * Resolves duplicate handles by incrementing the occurrence count
621
 * of the handle being created until there is no conflict.
628
 * of the handle being created.
622
 */
629
 */
623
protected void resolveDuplicates(SourceRefElement handle) {
630
protected void resolveDuplicates(SourceRefElement handle) {
624
	while (this.newElements.containsKey(handle)) {
631
	int occurenceCount = this.occurenceCounts.get(handle);
625
		handle.occurrenceCount++;
632
	if (occurenceCount == -1)
633
		this.occurenceCounts.put(handle, 1);
634
	else {
635
		this.occurenceCounts.put(handle, ++occurenceCount);
636
		handle.occurrenceCount = occurenceCount;
626
	}
637
	}
627
}
638
}
628
protected IMemberValuePair getMemberValuePair(MemberValuePair memberValuePair) {
639
protected IMemberValuePair getMemberValuePair(MemberValuePair memberValuePair) {

Return to bug 135906