Home » Language IDEs » Java Development Tools (JDT) » Performance Issues: IType - newTypeHierarchy(...)(Calling this method on special types takes over 1 sec)
Performance Issues: IType - newTypeHierarchy(...) [message #643159] |
Sun, 05 December 2010 14:38 |
Andreas Kaluza Messages: 10 Registered: December 2010 |
Junior Member |
|
|
Hello,
I'm currently working on a project, which supports the code recommender project proposed for eclipse (http://eclipse.org/proposals/code-recommenders/).
Within my project I have to test whether two types are in a subtype / supertype hierarchies or not. For this I use the JDT framework, which allows to create such type hierarchies (Interface IType - method: newTypeHierarchy(...) ).
My task requires to test for several type hierarchies. After implementing and benchmarking I got a bottle neck. One method call takes sometimes over one second, which makes my plug-in unusable.
I created a small test plug-in to visualize the context:
public class EntryPoint implements IJavaCompletionProposalComputer {
/**
* A cache for type hierarchies to avoid unnecessary computations
*/
private final Map<IType, ITypeHierarchy> hierarchies = new HashMap<IType, ITypeHierarchy>();
@Override
public List<?> computeCompletionProposals(
ContentAssistInvocationContext context, IProgressMonitor monitor) {
final JavaContentAssistInvocationContext jctx = (JavaContentAssistInvocationContext) context;
try {
IType lookupContext = jctx.getCompilationUnit().getJavaProject().findType("java.lang.String");
IType typeToCheck = jctx.getCompilationUnit().getJavaProject().findType("org.eclipse.ui.IWorkbench");
System.out.println(this.isSubtype(lookupContext, typeToCheck) + " " + this.isSupertype(lookupContext, typeToCheck));
} catch (JavaModelException e) {
e.printStackTrace();
}
return Collections.emptyList();
}
@Override
public List<?> computeContextInformation(
ContentAssistInvocationContext context, IProgressMonitor monitor) {
return Collections.emptyList();
}
@Override
public String getErrorMessage() {
return null;
}
@Override
public void sessionEnded() {
}
@Override
public void sessionStarted() {
}
/**
* Tests for subtype relation between two types in a (once created) type hierarchy
* @param context base type
* @param subtype type to test to be a subtype or not
* @return true, in case of subtype relation, else false
* @throws JavaModelException
* @see {@link #isSupertype(IType, IType)}
*/
public boolean isSubtype(IType context, IType subtype) throws JavaModelException {
long i = System.currentTimeMillis();
ITypeHierarchy hierarchy = hierarchies.get(context);
if (hierarchy == null) {
hierarchy = context.newTypeHierarchy(new NullProgressMonitor());
synchronized (hierarchies) {
hierarchies.put(context, hierarchy);
}
}
IType subtypes[] = hierarchy.getAllSubtypes(context);
boolean ret = Arrays.asList(subtypes).contains(subtype);
System.out.println("subtype: " + (System.currentTimeMillis() - i) + " " + context.getFullyQualifiedName() + " - " + subtype.getElementName());
return ret;
}
/**
* Tests for supertype relation between two types in a (once created) type hierarchy
* @param context concrete type
* @param subtype type to test to be a supertype or not
* @return true, in case of supertype relation, else false
* @throws JavaModelException
* @see {@link #isSubtype(IType, IType)}
*/
public boolean isSupertype(IType context, IType subtype) throws JavaModelException {
long i = System.currentTimeMillis();
ITypeHierarchy hierarchy = hierarchies.get(subtype);
if (hierarchy == null) {
hierarchy = subtype.newTypeHierarchy(new NullProgressMonitor());
synchronized (hierarchies) {
hierarchies.put(subtype, hierarchy);
}
}
IType subtypes[] = hierarchy.getAllSubtypes(subtype);
boolean ret = Arrays.asList(subtypes).contains(context);
System.out.println("supertype: " + (System.currentTimeMillis() - i) + " " + context.getFullyQualifiedName() + " - " + subtype.getElementName());
return ret;
}
}
The two methods at the end are the point of interest. They check whether one type is a subtype / supertype of the other one or not. In this demonstration this plug-in checks the types java.lang.String and org.eclipse.ui.IWorkbench. Of course the result is in both cases negative.
My question is:
- Is there another way to test for such sub- and supertype hierarchies?
- Do you know how to increase the performance?
Best Regards,
Andreas K.
|
|
|
Re: Performance Issues: IType - newTypeHierarchy(...) [message #643180 is a reply to message #643159] |
Sun, 05 December 2010 19:27 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Andreas,
I've experienced similar results with #newTypeHierarchy and finally
decided to collect the supertypes for both types by means of
#newSupertypeHierarchy and check whether the resultsets intersect.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 05.12.10 15:38, schrieb andy.kaluza@gmx.de:
> Hello,
>
> I'm currently working on a project, which supports the code recommender
> project proposed for eclipse
> (http://eclipse.org/proposals/code-recommenders/).
> Within my project I have to test whether two types are in a subtype /
> supertype hierarchies or not. For this I use the JDT framework, which
> allows to create such type hierarchies (Interface IType - method:
> newTypeHierarchy(...) ).
>
> My task requires to test for several type hierarchies. After
> implementing and benchmarking I got a bottle neck. One method call takes
> sometimes over one second, which makes my plug-in unusable.
>
> I created a small test plug-in to visualize the context:
>
>
> public class EntryPoint implements IJavaCompletionProposalComputer {
>
> /**
> * A cache for type hierarchies to avoid unnecessary computations
> */
> private final Map<IType, ITypeHierarchy> hierarchies = new
> HashMap<IType, ITypeHierarchy>();
>
> @Override
> public List<?> computeCompletionProposals(
> ContentAssistInvocationContext context, IProgressMonitor monitor) {
>
> final JavaContentAssistInvocationContext jctx =
> (JavaContentAssistInvocationContext) context;
> try {
> IType lookupContext =
> jctx.getCompilationUnit().getJavaProject().findType("java.lang.String ");
> IType typeToCheck =
> jctx.getCompilationUnit().getJavaProject().findType("org.eclipse.ui.IWorkbench ");
>
> System.out.println(this.isSubtype(lookupContext, typeToCheck) + " " +
> this.isSupertype(lookupContext, typeToCheck));
>
> } catch (JavaModelException e) {
> e.printStackTrace();
> }
> return Collections.emptyList();
> }
>
> @Override
> public List<?> computeContextInformation(
> ContentAssistInvocationContext context, IProgressMonitor monitor) {
> return Collections.emptyList();
> }
>
> @Override
> public String getErrorMessage() {
> return null;
> }
>
> @Override
> public void sessionEnded() {
>
> }
>
> @Override
> public void sessionStarted() {
> }
>
>
> /**
> * Tests for subtype relation between two types in a (once created) type
> hierarchy
> * @param context base type
> * @param subtype type to test to be a subtype or not
> * @return true, in case of subtype relation, else false
> * @throws JavaModelException
> * @see {@link #isSupertype(IType, IType)}
> */
> public boolean isSubtype(IType context, IType subtype) throws
> JavaModelException {
> long i = System.currentTimeMillis();
> ITypeHierarchy hierarchy = hierarchies.get(context);
> if (hierarchy == null) {
> hierarchy = context.newTypeHierarchy(new NullProgressMonitor());
> synchronized (hierarchies) {
> hierarchies.put(context, hierarchy);
> }
> }
> IType subtypes[] = hierarchy.getAllSubtypes(context);
> boolean ret = Arrays.asList(subtypes).contains(subtype);
> System.out.println("subtype: " + (System.currentTimeMillis() - i) + " "
> + context.getFullyQualifiedName() + " - " + subtype.getElementName());
> return ret;
> }
>
> /**
> * Tests for supertype relation between two types in a (once created)
> type hierarchy
> * @param context concrete type
> * @param subtype type to test to be a supertype or not
> * @return true, in case of supertype relation, else false
> * @throws JavaModelException
> * @see {@link #isSubtype(IType, IType)}
> */
> public boolean isSupertype(IType context, IType subtype) throws
> JavaModelException {
> long i = System.currentTimeMillis();
> ITypeHierarchy hierarchy = hierarchies.get(subtype);
> if (hierarchy == null) {
> hierarchy = subtype.newTypeHierarchy(new NullProgressMonitor());
> synchronized (hierarchies) {
> hierarchies.put(subtype, hierarchy);
> }
> }
>
> IType subtypes[] = hierarchy.getAllSubtypes(subtype);
> boolean ret = Arrays.asList(subtypes).contains(context);
> System.out.println("supertype: " + (System.currentTimeMillis() - i) + "
> " + context.getFullyQualifiedName() + " - " + subtype.getElementName());
> return ret;
> }
> }
>
>
> The two methods at the end are the point of interest. They check whether
> one type is a subtype / supertype of the other one or not. In this
> demonstration this plug-in checks the types java.lang.String and
> org.eclipse.ui.IWorkbench. Of course the result is in both cases negative.
>
> My question is:
> - Is there another way to test for such sub- and supertype hierarchies?
> - Do you know how to increase the performance?
>
> Best Regards,
>
> Andreas K.
|
|
| |
Goto Forum:
Current Time: Fri Apr 26 14:20:04 GMT 2024
Powered by FUDForum. Page generated in 0.03881 seconds
|