Bug 174299 - [performance]SystemView should make use of StructuredViewer elementMap
Summary: [performance]SystemView should make use of StructuredViewer elementMap
Status: RESOLVED FIXED
Alias: None
Product: Target Management
Classification: Tools
Component: RSE (show other bugs)
Version: 1.0.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 2.0   Edit
Assignee: David McKnight CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2007-02-15 08:20 EST by Martin Oberhuber CLA
Modified: 2008-08-13 13:17 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Oberhuber CLA 2007-02-15 08:20:31 EST
In Eclipse 3.2, the SWT StructuredViewer was enhanced to support mapping of data objects to TreeItems through an elementMap. This elementMap was specifically added in order to support a one-to-many mapping where the same data item is shown multiple times in the tree. For reference, see the Javadoc for StructuredViewer#findItems(Object element):

http://help.eclipse.org/help32/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/jface/viewers/StructuredViewer.html#findItems(java.lang.Object)

This is exactly the kind of use-case that's needed by the RSE SystemView.

Migrating the SystemView to this new SWT concept will help to reduce code, improve performance (through faster item lookups), and make the whole SystemView more configurable because the element comparer is exchangeable.

Supposedly, the following changes are required:
1.) In the SystemView constructors, call setUseHashlookup(true)
2.) In order to properly compare elements by both "absoluteName" and object,
    set a comparer:

    setComparer(new IElementComparer() {
      boolean equals(Object a, Object b) {
          if(a==b) return true;
          if(a==null || b==null) return false;
          if(a.equals(b)) return true;
          IRemoteObjectIdentifier identa;
          if(a instanceof IRemoteObjectIdentifier) {
              identa = ((IRemoteObjectIdentifier)a).getAbsoluteName();
          } else if(a instanceof IAdaptable) {
              identa = (IRemoteObjectIdentifier)
                 ((IAdaptable)a).getAdapter(IRemoteObjectIdentifier.class);
          }
          if(identa != null) {
              IRemoteObjectIdentifier identb;
              if(b instanceof IRemoteObjectIdentifier) {
                  identb = ((IRemoteObjectIdentifier)b).getAbsoluteName();
              } else if(b instanceof IAdaptable) {
                  identb = (IRemoteObjectIdentifier)
                     ((IAdaptable)b).getAdapter(IRemoteObjectIdentifier.class);
              }
              if(identa.equals(identb)) return true;
          }
          return false;
      }
      int hashCode(Object element) {
          IRemoteObjectIdentifier ident=null;
          if(element instanceof IRemoteObjectIdentifier) {
              ident = (IRemoteObjectIdentifier)element;
              String absName = ident.getAbsoluteName();
              if(absName!=null) return absName.hashCode();
              return element.hashCode();
          }
          if(element instanceof IAdaptable) {
              ident = (IRemoteObjectIdentifier)
                  ((IAdaptable)b).getAdapter(IRemoteObjectIdentifier.class);
              if(ident!=null) {
                  String absName = ident.getAbsoluteName();
                  if(absName!=null) return absName.hashCode();
                  return ident.hashCode();
              }
          }
          return element.hashCode();
      }
    });

3.) Get rid of methods recursiveFindAllRemoteItemReferences() and similar,
    using StructuredViewer.findElements() wherever possible
Comment 1 Martin Oberhuber CLA 2007-02-15 08:22:05 EST
Please consider for M6.

It's not only for performance and extensibility, but also brings us closer to the Eclipse Platform, so it might help migrating SystemView to other good concepts from the Platform like the Virtual Treeviewer, or the Asynchronous Treeviewer (currently in debug.internal but planned to become API)
Comment 2 David McKnight CLA 2007-04-02 11:39:19 EDT
SystemView now makes use of the elementMap where possible and falls back to recursive methods where the map fails.
Comment 3 Martin Oberhuber CLA 2008-08-13 13:17:40 EDT
[target cleanup] 2.0 M6 was the original target milestone for this bug