zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Helmut Jarausch <jarausch@igpm.rwth-aachen.de>, zsh-workers@zsh.org
Subject: Re: 100,000 calls to rt_sigprocmask for a single <Tab>?
Date: Mon, 21 Oct 2013 08:30:18 -0700	[thread overview]
Message-ID: <131021083018.ZM23575@torch.brasslantern.com> (raw)
In-Reply-To: <1382351360.2595.0@numa-i.igpm.rwth-aachen.de>

On Oct 21, 12:29pm, Helmut Jarausch wrote:
}
} ./hg<tab>
} 
} takes more than 20 seconds. An strace shows that zsh executes nearly  
} 100,000 calls to rt_sigprocmask

Zsh started fiddling with the WINCH signal pretty recently, May 2013.
System calls were getting interrupted by things like window managers
that move and resize windows automatically (probably for "zoom" visual
effects when popping open the terminal app) combined with terminal
emulators that start the shell before the window is fully opened.

It's a fairly nasty problem; you want the shell to respond relatively
quickly to the window size changing for visual feedback, but most of
the code has to keep the signal blocked so system calls aren't borked.
We adopted the strategy of unblocking the signal whenever the shell may
be blocked for some other reason (usually, input) and then blocking it
again immediately.

Given your description of the strace, the most likely bit of code to be
executing is input.c:shingetline() -- it's the only place where you'd
see unblock/block pairs without another system call (select or poll or
read) in between [because it's wrapped around fgetc() which buffers the
input so there needn't be a system call every time], and in that close
proximity to a memory allocation, and in a tight loop.

BUT ... that implies that a lot of input (50k or so, if it's 2600-some
unblock/block pairs repeated 20 times) is being consumed (e.g., by the
"source" or "." command).  Is it always 2602 unblock/block repeats or
does it vary?

Still, as a first check, you could try the patch below, which should
cut down the number of block/unblock pairs or at least reverse the
order you see them (i.e., the SIG_BLOCK should preceed SIG_UNBLOCK
in most of the repetitions).

If this does fix it, your next task would be to figure out why the
shingetline() call is happening during that particular completion.


diff --git a/Src/input.c b/Src/input.c
index 9bd9663..4ac7e6e 100644
--- a/Src/input.c
+++ b/Src/input.c
@@ -142,14 +142,14 @@ shingetline(void)
     char *p;
 
     p = buf;
+    winch_unblock();
     for (;;) {
-	winch_unblock();
 	do {
 	    errno = 0;
 	    c = fgetc(bshin);
 	} while (c < 0 && errno == EINTR);
-	winch_block();
 	if (c < 0 || c == '\n') {
+	    winch_block();
 	    if (c == '\n')
 		*p++ = '\n';
 	    if (p > buf) {
@@ -165,11 +165,13 @@ shingetline(void)
 	} else
 	    *p++ = c;
 	if (p >= buf + BUFSIZ - 1) {
+	    winch_block();
 	    line = zrealloc(line, ll + (p - buf) + 1);
 	    memcpy(line + ll, buf, p - buf);
 	    ll += p - buf;
 	    line[ll] = '\0';
 	    p = buf;
+	    winch_unblock();
 	}
     }
 }


      reply	other threads:[~2013-10-21 15:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-21 10:29 Helmut Jarausch
2013-10-21 15:30 ` Bart Schaefer [this message]

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=131021083018.ZM23575@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=jarausch@igpm.rwth-aachen.de \
    --cc=zsh-workers@zsh.org \
    /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).