grasping the data grid

Richard Gaskin ambassador at fourthworld.com
Tue Mar 31 11:27:59 EDT 2009


Bernard Devlin wrote:

> Following Trevor's mention that he'd used the data grid with 50,000
> rows from sqlite, I put 100,000 rows into a data grid.  It still
> sorted remarkably quickly - maybe 2 seconds to sort by a column and
> display it.  I'm assuming from his mention of optimization, that the
> data grid is really just a window onto a list, but if so, it appears
> seamless to me.

The ability to use groups within groups as a sort of custom "list 
definition" has been around since groups were first added to the engine; 
I've used them in my Sophie ebook reader, WebMerge and others, as have a 
good many other developers.

In principle it's simple enough:  make a group which acts as a template 
for the row, then clone that group within another group as needed to 
build out your complete list.

But using groups that way usually has at least two significant limitations:

1. The formattedHeight of a group is limited to 32,767 pixels (though a 
request has been submitted to raise that: 
<http://quality.runrev.com/qacenter/show_bug.cgi?id=1858>).

2. Attempting to create all rows of a given data set at once will yield 
thousands, or even tens of thousands, of objects, introducing memory issues.

And that's where Trevor's work becomes amazing:

Through what I can only imagine was a good many weeks of very long 
nights, he's worked out the math and management for using the 
groups-within-groups technique to build custom lists in a way that more 
closely resembles how the OS handles custom LDEFs under the hood, 
rendering only the controls that can be seen on screen and moving their 
contents from row to row as needed to emulate scrolling, all the while 
maintaining a scrollbar that represents the full data set even though 
most of that data set is never in actual objects on the card.

That he made this functional at all would be praise-worthy enough, but 
he's apparently put in much time to make sure it performs with amazing 
efficiency.

Extra bonus points that he's also crafted a very usable API for working 
with it.  Working with something as complex as the DataGrid will never 
be as simple as working with a native field object, given the range of 
things the DataGrid does.  But for all the flexibility of the DataGrid 
Trevor's API is quite learnable and well thought out.  The exchanges on 
the beta list have shown him to be flexible and responsive to 
suggestions to hone the API for this release, making ever more graceful 
to script for.

When you need an unusual list style, Trevor's tool is more than an 
adequate solution; I would argue that it's among the best possible 
solutions given the engine's current design.  His DataGrid plays well 
with the engine's strengths while avoiding its limitations.

A damn fine job, Trevor.

--
  Richard Gaskin
  Fourth World
  Revolution training and consulting: http://www.fourthworld.com
  Webzine for Rev developers: http://www.revjournal.com



More information about the use-livecode mailing list