benchmarks for the release

Stephen Weeks MLton@sourcelight.com
Mon, 1 Apr 2002 01:22:38 -0800


> In TextIO.inputLine, the following copies occur:
>     First the read system call copies the bytes into the buffer.
>     Second the inputLine code copies the next line in to a list.
>     Third the list is copied into an array (the final string).
> I am not proposing changing the string representation, but note that the only
> reason for the list is because you don't know how big the string is going  to
> be  until you get to the newline.  The alternative would be to keep a list of
> the buffers which have the current  line  (usually  just  1)  and  then  copy
> directly  from  them  into the final string.  This would require not re-using
> buffers, but that is very cheap compared to copying the line into a list.  In
> the end it changes the number of copies from 3 to 2.

Agreed, but the by far common case is that the line is seen within the
current buffer, in which case there are only two copies -- one for the
read system call and one for copying into the list.  The final concat
does not do a copy since the list is of length one.  So I'm still not
convinced it's worth changing.