Grid.addData performance

I picked up GridDataBoundAddSample.java in the SmartGWT Showcase,
and created a small app. It add 1 recode to grid per 1 button click.
The grid initialized over 200 records.

I modified code to add 2000 records per 1 click.

The result, Firefox3 6sec, GoogleCrhome1 5sec.
Oh, Excellent ! (Q9450 3GB WindowsXpSP3)

The grid source world.data.xml contains over 200 records(country) .
I edit this xml, almost threw away, and left only 3 records.
I tried agein.
The grid initialized only 3 records.
And click,…

Firefox3 120sec, GoogleChrome1 105sec.
20 times over? What happen ? I added same 2000 records.
It be only me?

	public void onModuleLoad() {
        Canvas canvas = new Canvas();  

        final ListGrid countryGrid = new ListGrid();  
        countryGrid.setWidth(500);  
        countryGrid.setHeight(224);  
        countryGrid.setAlternateRecordStyles(true);  
        countryGrid.setEmptyCellValue("-");  
        countryGrid.setDataSource(WorldXmlDS.getInstance());  
  
        ListGridField countryCodeField = new ListGridField("countryCode", "Country Code");  
        ListGridField nameField = new ListGridField("countryName", "Country");  
        ListGridField capitalField = new ListGridField("capital", "Capital");  
        ListGridField continentField = new ListGridField("continent", "Continent");  
        countryGrid.setFields(countryCodeField, nameField, capitalField, continentField);  
          
        countryGrid.setSortField(0);  
        countryGrid.setDataPageSize(50);  
        countryGrid.setAutoFetchData(true);  
        
        IButton addCountry = new IButton("Add new country");  
        addCountry.addClickHandler(new ClickHandler() {  
            public void onClick(ClickEvent event) {
            	////////// UPDATE start
                for(int i = 0; i < 2000; i++){
                    int number = getNextNumber();  
                    ListGridRecord rec = new ListGridRecord();
                    rec.setAttribute("countryCode", "A" + number);  
                    rec.setAttribute("countryName", "Country " + number);  
                    rec.setAttribute("capital", "Capital " + number);                 
                    countryGrid.addData(rec);    
                }
            	////////// UPDATE end
            }             
        });  
        addCountry.setLeft(0);  
        addCountry.setTop(240);  
        addCountry.setWidth(140);  
          
        canvas.addChild(countryGrid);  
        canvas.addChild(addCountry);  
  
        canvas.draw();  
    }

Not all browsers handle large datasets well, which is why you should lazy load the data on demand from the server rather than locally add many records. Have a look at the Showcase RestDataSource sample. The fetch request passing the start row, end row info and the response indicates the total rows. This way as the user scrolls, data is loaded from the server on-demand and only data being displayed + a configurable buffer region is actually stored in the browser.

Sanjiv

more strangeness

There is more strangeness.

The sample show cuntries on grid, see below.

Country Code
AA
AC
AF
…

The intial records are sorted.
AA is the top record.

I added 2000 records by button click, the generated country codes are from ‘A1’ to ‘A2000’,
Just grid redraw, it seems below.

Country Code
A2000
A1999
A1998
…

They are not sorted.

I scroll down and up in the range of added records, They are not sorted too.
When I scrolled down to bottom the grid,
and reached initial records deeply, all records are sorted suddenly.

Grids switch to client-side sort when the cache is full. Before then, only the server can perform sorting, and so dsRequests send to the server contain the requested sorting direction in dsRequest.sortBy.