Bug 470319 - [type hierarchy] Type Hierarchy view in 'Show the Supertype Hierarchy' mode automatically expands the entire tree
Summary: [type hierarchy] Type Hierarchy view in 'Show the Supertype Hierarchy' mode a...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 4.6 RC2   Edit
Assignee: Noopur Gupta CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2015-06-16 19:11 EDT by Slava Kabanovich CLA
Modified: 2016-05-19 01:48 EDT (History)
3 users (show)

See Also:
daniel_megert: review+
markus.kell.r: review+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Slava Kabanovich CLA 2015-06-16 19:11:48 EDT
The hierarchy may be constructed to have a huge number of nodes. Atomatical expanding the entire tree may hang Eclipse or crash it with out-of-memory.

See test project TypeHierarchyTest attached to https://bugs.eclipse.org/bugs/show_bug.cgi?id=469668
Load that project into workspace and try to show supertype hierarchy for interface hierarchy.I20. It will take cpu for a long time, and most probably hang Eclipse.
The project contains only 20 sources - interfaces extending each other.
Comment 1 Dani Megert CLA 2016-05-03 10:22:02 EDT
Not a regression compared to 3.x.
Comment 2 Eclipse Genie CLA 2016-05-11 08:42:34 EDT
New Gerrit change created: https://git.eclipse.org/r/72504
Comment 3 Noopur Gupta CLA 2016-05-11 08:47:18 EDT
Restricted the expansion to level 2, similar to the subtype hierarchy (as done in bug 31897). Dani, please have a look.
Comment 4 Dani Megert CLA 2016-05-11 14:10:57 EDT
(In reply to Noopur Gupta from comment #3)
> Restricted the expansion to level 2, similar to the subtype hierarchy (as
> done in bug 31897). Dani, please have a look.

This will reduce the usability for more users than it helps others. The supertype hierarchy is usually smaller than the subtype hierarchy.

Did you investigate what exactly takes that long?

Maybe we can find a dynamic limit, or expand as much as fits into the visible area. If not, we can set a limit, but higher, e.g. 5.
Comment 5 Dani Megert CLA 2016-05-12 02:26:29 EDT
(In reply to Dani Megert from comment #4)
> (In reply to Noopur Gupta from comment #3)
> > Restricted the expansion to level 2, similar to the subtype hierarchy (as
> > done in bug 31897). Dani, please have a look.
> 
> This will reduce the usability for more users than it helps others. The
> supertype hierarchy is usually smaller than the subtype hierarchy.
> 
> Did you investigate what exactly takes that long?
> 
> Maybe we can find a dynamic limit, or expand as much as fits into the
> visible area. If not, we can set a limit, but higher, e.g. 5.

Another solution could be to expand node-by-node and remember the nodes that are fully expand and when we see the same node again later in the tree, we don't expand it.
Comment 6 Noopur Gupta CLA 2016-05-13 06:55:41 EDT
(In reply to Dani Megert from comment #5)
> (In reply to Dani Megert from comment #4)
> > (In reply to Noopur Gupta from comment #3)
> > > Restricted the expansion to level 2, similar to the subtype hierarchy (as
> > > done in bug 31897). Dani, please have a look.
> > 
> > This will reduce the usability for more users than it helps others. The
> > supertype hierarchy is usually smaller than the subtype hierarchy.
> > 
> > Did you investigate what exactly takes that long?

YourKit shows that all the time is spent in recursive calls to 
AbstractTreeViewer.internalExpandToLevel(Widget widget, int level) and other methods called from it like #createChildren(Widget widget, boolean materialize) etc.

The view finally shows the complete expanded supertype hierarchy but only after an hour or so. It is just the huge number of recursive calls to #internalExpandToLevel due to the nature of the hierarchy in this example.

> Another solution could be to expand node-by-node and remember the nodes that
> are fully expand and when we see the same node again later in the tree, we
> don't expand it.
 
Uploaded patch set 2 on Gerrit with this behavior. Smaller example to see this:

package hierarchy;

public interface I1 extends X, A {}
interface X extends Y {}
interface Y extends Z {}
interface Z {}
interface A extends Y {}

Dani, please have a look.
Comment 7 Dani Megert CLA 2016-05-16 05:40:28 EDT
+1 to consider this fix for RC2.

Markus or Stephan, please provide the second +1 and review. Thanks.
Comment 8 Markus Keller CLA 2016-05-17 14:32:55 EDT
I agree that this should be fixed in RC2, and I agree with the fix strategy (only expand the first occurrence of any given type in the hierarchy), but I disagree with relying on undocumented implementation details, see Gerrit comment.
Comment 9 Noopur Gupta CLA 2016-05-18 02:58:15 EDT
In patch set 3, specifying the exact tree item to expand and using an explicit HashSet to collect the visited elements.
Comment 10 Dani Megert CLA 2016-05-18 10:03:03 EDT
(In reply to Noopur Gupta from comment #9)
> In patch set 3, specifying the exact tree item to expand and using an
> explicit HashSet to collect the visited elements.

+1 for this.
Comment 12 Markus Keller CLA 2016-05-18 10:38:03 EDT
+1. Patch set 3 changed the expansion strategy from breadth first to depth first. For the first visible page in the tree, that results in a state that looks even closer to the full expansion we had in earlier releases.
Comment 13 Dani Megert CLA 2016-05-19 01:48:11 EDT
Verified in eclipse-SDK-I20160518-2000-win32-x86_64.