[m-dev.] pprint performance

Kevin Glynn keving at cs.mu.OZ.AU
Mon Feb 25 17:12:37 AEDT 2002


I know nearly nothing about the problem you are solving,  but looking
at what you write below, isn't this really where laziness pays off?
Things are only calculated by demand,  so only enough of the 
internal data structures are calculated as needed to print each
character?  Of course its a disaster if the whole representation needs
to be calculated before you can print trhe first character,  but that
can usually be avoided.

I think this is where explicit laziness doesn't work, you can't just
make the outer call lazy, you havve to make all the internal parts
lazy too. Too painful.

k



Ralph Becket writes:
 > Peter Schachte, Monday, 25 February 2002:
 > > 
 > > Maybe instead of using an integer depth you could use
 > > 
 > > 	:- type depth_limit ---> none ; limit(int).
 > >
 > > [... good suggestion]
 > 
 > I think I've identified the real problem.
 > 
 > The steps involved in writing a term T are
 > 1. convert the term to a doc with D = to_doc(T),
 > 2. convert the doc to a list of strings for output,
 > 3. write out the list of strings.
 > 
 > For a term with a million nodes where each node is represented using
 > around ten strings (newlines, indents, brackets, commas, names, ...),
 > with each string costing two words per cons cell, we will consume of the
 > order of 80 MBytes just for the list of strings!
 > 
 > Most of the time we are just printing these strings, so we might as well
 > do it as we go rather than first collecting them in a list (the other
 > functionality provided is to concatenate them into a single string, but
 > that's a much lower priority problem.)
 > 
 > I'll try combining steps 2 and 3 so as not to construct an output list
 > and report back.
 > 
 > - Ralph
 > --------------------------------------------------------------------------
 > mercury-developers mailing list
 > Post messages to:       mercury-developers at cs.mu.oz.au
 > Administrative Queries: owner-mercury-developers at cs.mu.oz.au
 > Subscriptions:          mercury-developers-request at cs.mu.oz.au
 > --------------------------------------------------------------------------
 > 
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list