row-styles, transaction report

Bill Gribble grib@billgribble.com
Wed, 4 Apr 2001 08:06:42 -0500


rlb and I were trying to speed up the report system a bit recently.
He was using a big transaction report to test, and during the
debugging process I notice that the transaction-report uses row-styles
extensively (for every row, in fact).

I may not have mentioned this before, but row styles are a BIG
performance penalty, which is why I added the row-markup API.  It's
MUCH faster and does the same job as far as you are concerned (from
what I can tell, you are just setting bgcolor differently for
different rows, right?).  What you want to do is define new kinds of
markup at the table level which set rows the way you want:

  (gnc:html-table-set-style! 
   table "normal-row"
   'tag "tr"
   'attribute (list "bgcolor" normal-color))

  (gnc:html-table-set-style! 
   table "other-row"
   'tag "tr"
   'attribute (list "bgcolor" other-color))

Then, after you append the row, set the markup for it:

  ;; for normal rows 
  (gnc:html-table-set-row-markup! table row-num "normal-row")

  ;; for other rows
  (gnc:html-table-set-row-markup! table row-num "other-row")

Tables are a special case for the style system; with every row and
column possibly having different style tables, there's a unique "style
stack" for every cell, which means the styles can't be compiled in
advance and the code has to resort to a slower stack crawling approach
to find out how to render every tag and piece of data.  I have
optimized this for column styles, but row styles will always be a lose
and should only be used when you really need them (i.e. num-row-styles
<< num-rows).  Where possible, use table styles and special markup for
the row or cell.

For small reports with small tables row-styles are no big deal, but
transaction reports can have thousands of rows and performance can be
a real issue.

I hereby volunteer to eat my hat if you change over to using
row-markup and it doesn't make any significant performance difference
:)

b.g.