Bug 139700 Long delay on package explorer selection changes in large workspace
Build: Eclipse 3.2 RC2 I created a workspace with every callisto project added (600 projects). Clicking around in the Navigator, I found a long delay responding to selection changes (2-3 seconds on a dual 3 Ghz machine with 1024 MB RAM). The culprit is CloseUnrelatedProjectsAction.getSelectedResources. The algorithm it uses for computing the set of "unrelated projects" is O(N^3) on the number of projects in the worst case (the worst case being where all N projects are tightly related to each other, as in the Callisto project case). This should be fixed for 3.2, either by improving the algorithm, or not updating the set of unrelated projects when the selection changes. It currently does this in order to update the enablement of the action (disabling the action when there are no open unrelated projects).
bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/actions/CloseUnrelatedProjectsAction.java
* Computes the related projects of the selection.
	 */
	private void computeRelated(List selection) {
		HashSet relatedProjects = new HashSet();
		for (Iterator it = selection.iterator(); it.hasNext();) {
			Object next = it.next();
			if (next instanceof IProject) {
				addRelatedProjects(relatedProjects, (IProject) next);
			}
		}
		HashSet unrelated = new HashSet();
		unrelated.addAll(Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects()));
		unrelated.removeAll(relatedProjects);
		projectsToClose.clear();
		projectsToClose.addAll(unrelated);
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.actions.SelectionListenerAction#getSelectedResources()
	 */
	protected List getSelectedResources() {
		if (selectionDirty) {
			List newSelection = super.getSelectedResources();
			if (!oldSelection.equals(newSelection)) {
				oldSelection = newSelection;
				computeRelated(newSelection);
			}
			selectionDirty = false;
		}