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:
- The retrieval of all the model objects from the viewer’s input (it’s the content provider’s job).
- 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 …
April 16, 2008 at 4:02 pm |
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
April 16, 2008 at 6:40 pm |
https://bugs.eclipse.org/bugs/show_bug.cgi?id=161435
The debug framework has its own asynchronous viewer framework with some filtering capability (no sorting). There has been ongoing discussions about making the API available outside of debug, possibly combing work done by JFace.
April 16, 2008 at 7:10 pm |
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
April 16, 2008 at 10:33 pm |
The JFace request is Bug 157228
April 17, 2008 at 5:49 am |
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)
April 17, 2008 at 11:18 am |
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.
April 17, 2008 at 11:19 am |
Do you by chance have a small test-case I can run to see what’s going wrong with TreeViewers?
April 21, 2008 at 8:12 am |
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 ?
March 5, 2009 at 8:00 pm |
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!