[racket] Does Racket GUI scale?

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Thu Jul 10 18:37:45 EDT 2014

Dmitry Pavlov wrote at 07/09/2014 04:50 AM:
> I have to do a simple spreadsheet editor and I wonder
> whether Racket suits my needs. The main challenge
> is that the spreadsheet editor should be able to edit
> tables as big as 1000x1000 or 10000x100 cells.

For a million cells like that, when using any language and toolkit that 
I know of, I would probably implement it with a mix of manual drawing 
and using the occasional toolkit widgets in only small numbers at a time 
(only for actively editing of a single cell).

Fortunately, doing the drawing and mouse-click object picking for a grid 
is very easy to do efficiently and scalably, and doing it with 
scrollbars is only a little bit more arithmetic.  (If it were 2D objects 
of arbitrary shape, position, and layering, then that would be harder to 
do scalably, and likely require fancy data structures to do fast, but 
simple spreadsheet-like grids are easy.)

I would first try it with a full redraw of the visible part of the grid 
at each repaint/expose event.  If that flickered, I would add 
double-buffering to the full redraw.  If there was still something slow 
(say, if your anti-aliased text drawing was unusually slow while 
scrolling or when redrawing on-the-fly while typing the edited contents 
of a cell), then I would look at delaying/coalescing updates, or 
simplifying the intermediate updates before getting to an idle update 
when the full detail is done.  As an extreme last resort, I would look 
at doing partial (damage region) redraws to a double-buffer and block 
moves within the buffer for scrolling and window resizes, but this is 
more complicated and a likely source of hard-to-QA bugs.  I doubt that 
you will need the extreme last resort, so it should be pretty 
straightforward.

For editing the contents of cells in this manually-drawn grid, you can 
put the GUI toolkit editing controls:
* permanently in the enclosing GUI toolkit window (beside the grid, not 
over it),
* in a transient pop-up window of some kind, or
* transiently in-place over the grid (with pixel-exact position and 
geometry).

I think that this simple approach of a manually-drawn grid and minimal 
use of toolkit controls will be fast with even a million cells, without 
much programming difficulty.

Neil V.


Posted on the users mailing list.