[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

string port slow output on big string

From: Kevin Ryde
Subject: string port slow output on big string
Date: Mon, 14 Feb 2005 11:22:04 +1100
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux)

I tried writing a biggish string to a string port, and it was very
slow.  Eg.

    (use-modules (ice-9 time))
    (let ((str (make-string 100000 #\x)))
      (call-with-output-string (lambda (port)
                                 (time (display str port))))

gives on my poor 333mhz

    clock utime stime cutime cstime gctime
     7.63  7.58  0.05   0.00   0.00   4.17

I struck this trying to use regexp-substitute/global on a file slurped
into memory.  It was 130k, which is a decent size, but it's well
within the realm of reason.

I think strports.c st_write ends up doing a realloc and copy every 80
bytes of the block it's writing.  It knows the size, but it lets
st_flush just grow by 80 bytes at a time.

The change below speeds it up from 7 seconds to 10 ms for me.

But I don't know if the read side bits of this change are right.  Is
it supposed to update read_pos, read_end and read_buf_size to be the
end of the string, or something?

(Of course what would be even nicer would be to avoid big reallocing
altogether, like keep a list of chunks and only join them when a
get-string call wants the entire block.  But that can wait.)

Attachment: strports.c.write.diff
Description: Text Data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]