Bug 43766 [reconciling] ResourceMarkerAnnotationModel listener taking a long time
Build: I20030925 I was investigating a situation where adding breakpoints to a large file was very slow. It can take up to a second to add a breakpoint to a file such as Workspace.java (2000 lines). Almost all of this time is in the resource change listener added by ResourceMarkerAnnotationModel. First, a minor issue: Instead of adding a resource change listener that traverses the entire delta, you can locate a given resource delta within the resource change delta very quickly using IResourceDelta.findMember(): public void resourceChanged(IResourceChangeEvent e) { IResourceDelta delta= e.getDelta(); if (delta != null) { IResourceDelta child = delta.findMember(fResource.getFullPath()); if (child != null) update(child.getMarkerDeltas()); } } However, this was only a small speed improvement. The main problem is that the entire compilation unit is reparsed every time a breakpoint is added. I have added a profiler trace of where the time is going for adding a single breakpoint.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/filebuffers/CompilationUnitDocumentProvider2.java
int length= problem.getSourceEnd() - problem.getSourceStart() + 1;
				if (length < 0)
					return null;
					
				return new Position(start, length);
			}
			protected void update(IMarkerDelta[] markerDeltas) {
	
				super.update(markerDeltas);
				if (markerDeltas != null && markerDeltas.length > 0) {
					try {
						if (fCompilationUnit != null)
							fCompilationUnit.reconcile(true, null);
					} catch (JavaModelException ex) {
						if (!ex.isDoesNotExist())
							handleCoreException(ex, ex.getMessage());
					}
				}
			}
			
			/*
			 * @see IProblemRequestor#beginReporting()
			 */
			public void beginReporting() {
				if (fCompilationUnit != null && fCompilationUnit.getJavaProject().isOnClasspath(fCompilationUnit))
					fCollectedProblems= new ArrayList();
				else
					fCollectedProblems= null;
			}