The Artima Developer Community
Sponsored Link

Java Buzz Forum
JFace TableViewer Performance Mystery Solved

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Scott Delap

Posts: 1154
Nickname: scottdelap
Registered: Sep, 2004

Client / Server application developer.
JFace TableViewer Performance Mystery Solved Posted: Feb 17, 2005 10:10 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Scott Delap.
Original Post: JFace TableViewer Performance Mystery Solved
Feed Title: ClientJava.com
Feed URL: http://www.clientjava.com/archives/wireless_mobile.rdf
Feed Description: Client/Desktop Related Java Development
Latest Java Buzz Posts
Latest Java Buzz Posts by Scott Delap
Latest Posts From ClientJava.com

Advertisement

This week I was given the task of optimizing the performance of UI using a JFace TableViewer. After profiling things, I noticed that adding a simple row was resulting in 1000's of comparisons on a large table. This seemed odd to me so I checked out the JFace code to see just what was going on. The indexForElement method uses a binary search to find where an element should be inserted. Here is an excerpt of the method.

// find first item > element
while (compare == 0) {
    ++mid;
    if (mid >= count) {
        break;
    }
    data = table.getItem(mid).getData();
    compare = sorter.compare(this, data, element);
}
return mid;

Basically when an equal element in the eyes of the sorter is found, the method increments through the elements in the table until it finds one that is different. This becomes the insertion point.

So what is the problem? Well the code I was working on contained a sorter that had an "unsorted" state in addition to a sorted one. In this case it returned 0 for all comparisions between elements. This turned the performance of the indexForElement method to N/2 for all you Big O fans. This implementation is also a problem for tables that contain large numbers of equal items as well. While the performance of the indexForElement method wouldn't necessarily be N/2 it would still be slower than it has to be.

There are a number of solutions to my problem. First, I could have changed the sorter to return something besides 0. This wasn't really the problem though. Instead I extended TableViewer and overrode the indexForElement to return the index of the first row found whose comparison is equal to the target element. This results in the element being inserted in an order that is consistent with sorting. However there is no guarantee where in a block of equal rows a new element will be inserted.

The moral of this blog entry is that the default algorithms that an API uses aren't always the best for all cases.

Read: JFace TableViewer Performance Mystery Solved

Topic: Jython and Perl benchmark Previous Topic   Next Topic Topic: Context Reloading in Tomcat 5.5.7

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use