Bug 70856 [Viewers] ComboViewer internalRefresh is slow
When you call ComboViewer internalRefresh (via StructuredViewer.refresh), the viewer clears the model, gets the list of items from the data model and walks through them one by one, adding them to the combo and the element map: ILabelProvider labelProvider= (ILabelProvider) getLabelProvider(); for (int i= 0; i < children.length; i++) { Object el = children[i]; listAdd(labelProvider.getText(el), i); listMap.add(el); mapElement(el, list); // must map it, since findItem only looks in map, if enabled } However, this is a slow process because listAdd() calls combo.add(), which copies over the current list and adds one item to it. So in my list of 376 items, 376 new Arrays are created, weahc one larger than the last, and 376 arrayCopy's are done and combo.setItems() is callled 376 times, and from my profiling, it looks like a lot of time is spent in setItems. Would it be better to do: ILabelProvider labelProvider= (ILabelProvider) getLabelProvider(); String[] items = new String[children.length]; for (int i= 0; i < children.length; i++) { Object el = children[i]; //listAdd(labelProvider.getText(el), i); item[i] = labelProvider.getText(el); listMap.add(el); mapElement(el, list); // must map it, since findItem only looks in map, if enabled } listSetItems(items); which will call combo.setItems() only once? I have not been able to test this, because of the listMap variable referred to above is private and I can't subclass ComboViewer anyway because it is final.
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractListViewer.java
* @param element
     * @return String. Return the emptyString if the labelProvider
     * returns null for the text.
     */
    private String getLabelProviderText(ILabelProvider labelProvider, Object element){
    	String text = labelProvider.getText(element);
        if(text == null)
        	return "";
        return text;
    }
    /**
     * Adds the given element to this list viewer.
     * If this viewer does not have a sorter, the element is added at the end;
     * otherwise the element is inserted at the appropriate position.
     * <p>
     * This method should be called (by the content provider) when a single element 
     * has been added to the model, in order to cause the viewer to accurately
     * reflect the model. This method only affects the viewer, not the model.
     * Note that there is another method for efficiently processing the simultaneous
     * addition of multiple elements.
     * </p>
     *
     * @param element the element
     */
    public void add(Object element) {
        add(new Object[] { element });
    }
    /* (non-Javadoc)
     * Method declared on StructuredViewer.
     * Since SWT.List doesn't use items we always return the List itself.