From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17537 invoked from network); 17 Dec 1999 10:40:25 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 17 Dec 1999 10:40:25 -0000 Received: (qmail 18273 invoked by alias); 17 Dec 1999 10:40:15 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9098 Received: (qmail 18265 invoked from network); 17 Dec 1999 10:40:12 -0000 Date: Fri, 17 Dec 1999 11:40:09 +0100 (MET) Message-Id: <199912171040.LAA09780@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk In-reply-to: "Bart Schaefer"'s message of Fri, 17 Dec 1999 07:16:10 +0000 Subject: 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@informatik.hu-berlin.de