Project: JDT
Bug 84224 Need advice for finding duplicate Types
Reported: 2005-02-02 09:39:15 | Status: verified fixed

To get rid of the all types cache we have done several performance measurements how to best calculate the number of duplicate types names (e.g. same type name, but in different package). This information is essential for the organize import actions and the import rewriter. In a workspace containing all SDK plug-ins there are 1798!! duplicate type names: The different searches we tested. - searching for all types in a given scope. For example all types visible in org.eclipse.jdt.ui. This reports 20671 matches and takes between 1.31 s and 1.86 s without us doing any analysis to find duplicate types. - we search for all type names in a given type-container. A type container is either a package or a type with it package qualification if it is a nested type (e.g. pack.Type.InnerType the type container is pack.Type). Such a search doesn't exist yet, but we simulated it with a package as a type container. The result for the package "org.eclipse.jdt.internal.ui.text" is 89 types and takes between 220 ms and 250 ms. For the organize import we would search for all type containers which have a star import (e.g. end with '*'). Doing this in a loop we will spend the same time as for the all types search when searching for 4 - 5 type containers. If clients use star imports they will easily have 4 - 5 star imports. - We search for duplicate types for all types that are used unqualified in the source code to see if we have more than one match. For Assert in the scope of org.eclipse.jdt.ui we get 13 matches. This takes between 140 and 190 ms. The current results aren't in a range where we can convert the import structure to use the search engine without having a noticable performance degradation. So the question is: - is there a better search/algorithm we can use ? - can we add a special query to the search engine which than can be optimized ? For example a search query that reports all types in an array of type containers so that we only scan the index once.

Files changed in fix:
org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportsStructure.java