Bug 211507 - [Viewers] Sorting a TableViewer using a ViewerSorter is very slow
Summary: [Viewers] Sorting a TableViewer using a ViewerSorter is very slow
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2.2   Edit
Hardware: PC Windows XP
: P3 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact: Hitesh CLA
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2007-11-29 15:19 EST by David Heath CLA
Modified: 2013-03-05 12:18 EST (History)
1 user (show)

See Also:


Attachments
Example program to demonstrate sort speeds (6.53 KB, text/plain)
2007-11-29 15:19 EST, David Heath CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Heath CLA 2007-11-29 15:19:44 EST
Created attachment 84102 [details]
Example program to demonstrate sort speeds

Build ID: M20070212-1330

Steps To Reproduce:
1.Compile and run the attached program.
2.Clicking on Column 1 will print out the time to perform the sorting of the data and also the time to complete the table sort.
3.Clicking on Column 2 will print out the time to refresh the table.


More information:
In order to get the time for the data sort I override the sort method on MyViewerSorter and time the call to super.sort().

I added timing for refresh as after looking into the source code I noticed installing a new sorter invokes the refresh() method.

As can be seen for a 10,000 row table refresh times are less then 0.02 seconds, the time to sort the actual data is also less then 0.02 seconds, however the total time to sort and refresh the table is often over 3 seconds. My guess is the time is taken re-indexing the rows.
Comment 1 Boris Bokowski CLA 2007-11-30 16:49:50 EST
Have you tried this:

tableViewer.getTable().setRedraw(false);
try {
  tableViewer.refresh();
} finally {
  tableViewer.getTable().setRedraw(true);
}
Comment 2 David Heath CLA 2007-11-30 17:13:45 EST
Your suggestion makes a big difference - total time to sort the table is now down to under .1 seconds (compared to over 3 seconds).

However, everywhere I change the table sorter my code now looks like:

              _viewer.getTable().setRedraw(false);
              try {
                _viewer.setSorter(new MyViewerSorter(up));
                _viewer.refresh();
              }
              finally {
                _viewer.getTable().setRedraw(true);
              }

Which is OK - however would it not be possible to enable and disable the redraw within the 

TableViewer.setSorter()

method?
Comment 3 Boris Bokowski CLA 2007-11-30 17:17:53 EST
We don't like to call setRedraw() on behalf of clients because they guarantee flicker at the setRedraw(true) time. If you have very few items, there is no performance gain, and should you call many methods that turn off/on redraw after another, it would lead to a lot of flicker.
Comment 4 David Heath CLA 2007-11-30 17:22:17 EST
OK - but how does the average user know that they should disable redraw when they change the sorter for a large table?

Could you not add another setSorter method which takes a boolean which would disable the redraw - Adding this method would at least place something in the JavaDoc.
Comment 5 Boris Bokowski CLA 2009-11-26 09:50:13 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 6 Lars Vogel CLA 2013-03-05 12:18:28 EST
According to the Javadoc ViewerSorter has been replaced with ViewerComparator. Also given the age of this bug, it seems unlikely that this bug will get attention. Therefore I close this bug, as WONTFIX. 

If you see the same problem with ViewerComparator please open a new bug.