Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] any plan for supporting windows 2003 server?

Hi,

 

Is there a plan for supporting windows 2003 server?

 

James

-----Original Message-----
From: Steve Northover [mailto:Steve_Northover@xxxxxxxxxx]
Sent:
Tuesday, April 08, 2003 9:07 AM
To: platform-swt-dev@xxxxxxxxxxx
Cc: platform-swt-dev@xxxxxxxxxxx; platform-swt-dev-admin@xxxxxxxxxxx
Subject: Re: [platform-swt-dev] Win32 table speedup

 


Ed, thanks for the interest and the code.  Table speed ups are on the 2.2 plan.  Normally, SWT is optimized for space.  That's why things grow slowly.  A better idea than guessing at how to grow the table is to allow the programmer to specify a size hint (ie. Table.setItemCountHint() or something ... we need a better name).  That way, there would be no growing at all.  The other change, doing the indexof() from the end is not harmful but optimizes one case over another.  The algorithm is still O(n^2).  This might be the right optimization to make.

The thing that really bothers me is that it still takes 1 minute to add 400,000 items.  I realize it takes longer without the optimizations but 1 minute is still too long for a user to wait.

I'm having Felipe create a benchmark and gather the numbers.  Here is the PR we are using to track this issue:

http://bugs.eclipse.org/bugs/show_bug.cgi?id=36226

Please add yourself, your ideas and any code to this PR.  Thanks.


 

"Ed Burnette" <Ed.Burnette@xxxxxxx>
Sent by: platform-swt-dev-admin@xxxxxxxxxxx

04/06/2003 10:59 PM
Please respond to platform-swt-dev

       
        To:        <platform-swt-dev@xxxxxxxxxxx>
        cc:        
        Subject:        [platform-swt-dev] Win32 table speedup




I was having trouble putting more than a couple thousand items in a table on Windows so I took a look at the code and found a couple areas that could be sped up. Could someone take a look at these changes to see if they look reasonable? If so I'd like to contribute them to the code base. With the changes I can add about 400,000 table items a minute to a table.

The first part of the patch is in Table.createItem(TableItem, int). I noticed that it was reallocating and copying the items array every fourth time an item was added, leading to an O(n^2) time for creating an item. I fixed this by increasing the items array by 50% each time. You could try 75% or 100% but this is what I typically use in my own code.

The second 2 parts are in the Table.indexOf(TableColumn) and Table.indexOf(TableItem) methods. I noticed that typically one will add items to the bottom of the table and then call TableItem.setText() to set their text. Unfortunately this turns around and calls Table.indexOf(this), which was searching all the way from the beginning of the list for the item that was just added to the end. Another O(n^2) algorithm. I fixed this by searching backwards through the table items instead, and did the same for columns for consistency. If any code is relying on the indexOf searching forwards it would break that code, but I couldn't think of a reason why you'd have duplicate items or columns anyway, can you? If there's a reason then perhaps another way could be devised to prevent the extra search such as keeping track of the last item added or using a hash instead of a linear search (though a hash wouldn't guarantee the order either).

At the end of this message I've included a little test program that I tweaked from an original newsgroup message by Steve Northover.

Index: Table.java
===================================================================
RCS file: /home/eclipse/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java,v
retrieving revision 1.65
diff -u -r1.65 Table.java
--- Table.java                
1 Apr 2003 21:10:14 -0000                 1.65
+++ Table.java                
7 Apr 2003 02:31:40 -0000
@@ -335,7 +335,7 @@
                 int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
                 if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
                 if (count == items.length) {
-                                  TableItem [] newItems = new TableItem [items.length + 4];
+                                  TableItem [] newItems = new TableItem [(items.length*3)/2 + 4];
                                  System.arraycopy (items, 0, newItems, 0, items.length);
                                  items = newItems;
                 }
@@ -1006,10 +1006,9 @@
}

/**
- * Searches the receiver's list starting at the first column
- * (index 0) until a column is found that is equal to the
- * argument, and returns the index of that column. If no column
- * is found, returns -1.
+ * Searches the receiver's list until a column is found that is equal to the
+ * argument, and returns the index of that column. If no column is found, returns -1.
+ * The search order is unspecified.
 *
 * @param column the search column
 * @return the index of the column
@@ -1027,17 +1026,16 @@
                 if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
                 int hwndHeader =  OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
                 int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
-                 for (int i=0; i<count; i++) {
+                 for (int i=count-1; i>= 0; i--) {
                                  if (columns [i] == column) return i;

                  }
                 return -1;
}

/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
+ * Searches the receiver's list until an item is found that is equal to the
+ * argument, and returns the index of that item. If no item is found, returns -1.
+ * The search order is unspecified.
 *
 * @param item the search item
 * @return the index of the item
@@ -1054,7 +1052,7 @@
                 checkWidget ();
                 if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
                 int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
-                 for (int i=0; i<count; i++) {
+                 for (int i=count-1; i>= 0; i--) {
                                  if (items [i] == item) return i;
                 }
                 return -1;


Test program follows:


import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

/*
* Created on
Apr 6, 2003
*/

/**
* @author sasebb
* Adapted from an example by Steve Northover at:
* http://dev.eclipse.org/newslists/news.eclipse.tools/msg23560.html
* Changes include
*  - ability to add more than one row at a time (curiously this didn't make a huge difference)
*  - define a column and set a width on it. This did make a huge difference because otherwise
*    the code goes through all the previous items every time you add a new one to find the
*    maximum width.
*/
public class
Main {
  // So you can play around with adding more than one at a time
  static final int INCR = 100;

  public static void main(String[] args) {
     final Display display = new Display();
     final Image image = new Image(display, 16, 16);
     GC gc = new GC(image);
     gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
     gc.fillRectangle(image.getBounds());
     gc.dispose();
     final Shell shell = new Shell(display);
     shell.setText("Lazy Table");
     shell.setLayout(new FillLayout());
     final Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
     table.setSize(200, 200);
     TableColumn column = new TableColumn(table, SWT.NONE);
     column.setText("A Column"); // for best results there must be a column
     column.setWidth(150); // and the column must have a width
     table.setHeaderVisible(true); // doesn't matter if it's visible or not
     Thread thread = new Thread() {
        public void run() {
           for (int i = 0; i < 100000; i += INCR) {
              if (table.isDisposed())
                 return;
              final int[] index = new int[] { i };
              display.syncExec(new Runnable() {
                 public void run() {
                    if (table.isDisposed())
                       return;
                    for (int j = 0; j < INCR; j++) {
                       TableItem item =
                          new TableItem(table, SWT.NULL, (index[0] + j));
                       item.setText("Table Item " + (index[0] + j));
                       //item.setImage(image);
                    }
                 }
              });
           }
        }
     };
     thread.start();
     shell.setSize(200, 200);
     shell.open();
     while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
           display.sleep();
     }
     image.dispose();
     display.dispose();
  }
}

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top