JFace’s Viewers Performances


Last weeks I played for the first time with JFace’s viewers (TableViewer and TreeViewer). It was really easy to integrate my first viewers inside my own Eclipse views.

All was working fine when I started to encounter performances problems when setting inputs containing thousands of entries (several seconds for ~50.000 rows in a TableViewer).

A quick look on Google pointed me to LAZY content providers and SWT.VIRTUAL in order to improve performances. Before going further with these content providers we have to identify bottle necks. When working with JFace’s viewers there is potentially 2 bottle necks:

  1. The retrieval of all the model objects from the viewer’s input (it’s the content provider’s job).
  2. The creation of UI elements.

As Tom Schindl said here (Snippet 29): “The bottle neck is often the UI and not the model“.

I checked the time consumed in my content provider to retrieve viewer’s entries. Only few milliseconds. My bottle neck is the UI !!

To solve this performances problem I just added the SWT.VIRTUAL style when creating my TableViewer. Creating the viewer this way tells JFace to create the SWT's TableItem objects on an on demand basis. TableItem objects are created only when they become visible (when the user scroll for example). As a conclusion, all I had to do to solve my performances problem is to set this magic style: SWT.VIRTUAL. It’s so easy to work with Eclipse !!!!! Isn’t it ??

Next i tried the same solution with TreeViewer. Unfortunately it didn’t worked. I had to use the SWT.VIRTUAL style WITH an ILazyTreeContentProvider in order to increase my performances as in TableViewer. It’s fine but this solution has one drawback: Sorting and Filtering are no longer available when using ILazyTreeContentProvider.

Someone told me on the Eclipse Platform newsgroup that the request to support SWT.VIRTUAL style and sorting and filtering for TreeViewer is already in the “pipe” but i can’t find such a request on Eclipse bugzilla. If someone can tell me more on that …

Advertisements

9 thoughts on “JFace’s Viewers Performances

  1. Hi,

    Our experience in RSSOwl2 has also been that the creation of UI elements is the bottleneck.

    “Someone told me on the Eclipse Platform newsgroup that the request to support SWT.VIRTUAL style and sorting and filtering for TreeViewer is already in the “pipe””

    That’s interesting. We would benefit from that too.

    Ismael

  2. Hi Manuel,

    50 000 rows is not so big.
    If you really want sorting and filtering, perhaps you can do that at model level (ContentProvider level) instead of at UI level ?

    XR

  3. Thanks to all for your answers,

    I will keep an eye on the bug #157228.

    Xavier, i will get a try concerning sorting and filtering at model level, and of course let you know ;o)

  4. A thing that makes me think is way a TreeViewer in VIRTUAL-Mode with an ordinary content provider has performance problems because it should create the TreeItems only when shown. Need to investigate that a bit.

  5. Hi Tom,

    When you said : “Using a TreeViewer in VIRTUAL-Mode with an ordinary content provider should create the TreeItems only when shown” does it mean all TreeItems are created lazily or only “Children” items ?

    In fact I forgot to mention in my post than my TreeViewer mainly contains “Root elements” (only ~1% of the 60 000 entries have a parent).
    So what I mean by “Performances Problems” is : Root elements are all created at once even if they are not visible.

    The snippet 02 in the JFace’s snippets can be used to reproduce this …

    In fact I just had a quick look into TreeViewer class and the following lines made me think that VIRTUAL style must be used with Lazy content providers:

    treeControl.addListener(SWT.SetData, new Listener() {
    public void handleEvent(Event event) {
    if (contentProviderIsLazy) {
    TreeItem item = (TreeItem) event.item;
    …..
    }
    }
    });

    If my viewer doesn’t have a LazyContentProvider the SWT.SetData listener isn’t used … Am I right or did I miss something ?

  6. Hi,

    I did a model level sort, it works fine except when adding dynamically an item that should occupy the first position, the tree is no longer coherent!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s