zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: Re: zsh and memory
Date: Fri, 17 Dec 1999 11:40:09 +0100 (MET)	[thread overview]
Message-ID: <199912171040.LAA09780@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: "Bart Schaefer"'s message of Fri, 17 Dec 1999 07:16:10 +0000


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


             reply	other threads:[~1999-12-17 10:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-17 10:40 Sven Wischnowsky [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-12-17 11:49 Sven Wischnowsky
1999-12-16 10:39 Sven Wischnowsky
1999-12-16 11:16 ` Mike Fletcher
1999-12-16 18:01 ` Timothy Writer
1999-12-16  9:56 Sven Wischnowsky
1999-12-17  7:16 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199912171040.LAA09780@beta.informatik.hu-berlin.de \
    --to=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).