Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh and memory



Bart Schaefer wrote:

> On Dec 16, 10:56am, Sven Wischnowsky wrote:
> } Subject: Re: zsh and memory
> }
> } [...] I looked who was using lots of heap memory and found the
> } tokstr handling in lex.c. There we always allocate at least 256 bytes
> } and if the buffer needs expanding (in add()) in gets resized to
> } inbufct (or larger). Some more investigation showed that we almost
> } never need a tokstr with more than 32 bytes, so I changed that.  I also 
> } changed add() to be more careful when expanding the buffer -- I left
> } the old code conditioned out because I don't kno if there was a reason 
> } to resize it to inbufct bytes; I at least don't see a reason for that.
> 
> Probably the idea was to eliminate lots of small allocations in the
> event that the "token" is a long quoted string or the like, for speed.
> We should watch out for performance problems if those changes are kept.

I know, but always enlarging the buffer to inbufct chars means that
if a somewhat longer string in an autoloaded function is encountered,
the buffer is enlarged to the size of the function file. And this will 
only seldom (never?) be the right thing.

The patch below goes on top of the previous one and doubles the size
of the buffer in add(), limiting it to inbufct chars. I hope, this is
a good compromise.

Bye
 Sven

diff -ru ../z.old/Src/lex.c Src/lex.c
--- ../z.old/Src/lex.c	Fri Dec 17 10:04:36 1999
+++ Src/lex.c	Fri Dec 17 11:36:08 1999
@@ -480,7 +480,10 @@
 	bsiz = newbsiz;
 #endif
 
-	int newbsiz = bsiz + 32;
+	int newbsiz = bsiz * 2;
+
+	if (newbsiz > inbufct && inbufct > bsiz)
+	    newbsiz = inbufct;
 
 	bptr = len + (tokstr = (char *)hrealloc(tokstr, bsiz, newbsiz));
 	bsiz = newbsiz;

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author