zsh-workers
 help / color / mirror / code / Atom feed
From: Zoltan Hidvegi <hzoli@cs.elte.hu>
To: schaefer@nbn.com
Cc: zsh-workers@math.gatech.edu
Subject: Re: The speed of zsh
Date: Sun, 25 Aug 1996 16:25:00 +0200 (MET DST)	[thread overview]
Message-ID: <199608251425.QAA25213@hzoli.ppp.cs.elte.hu> (raw)
In-Reply-To: <960824141541.ZM453@candle.brasslantern.com> from Bart Schaefer at "Aug 24, 96 02:15:41 pm"

> } Somehow ksh spawns external commands twice as fast as zsh.
> 
> I suspect it has something to do with zsh's use of pipes for synchronizing
> parent and child processes; the zsh parent doesn't do anything until the
> child finishes its entersubsh() and closes the pipe.  Ksh probably doesn't
> create the pipe in the first place.

It the script I tried there was only a process substitution which does not
use synch pipes.  Anyway I did remove synch calls and it did make zsh a bit
faster even when it executed scripts which never before used synch perhaps
because of the better use of CPU cache.  And I now discovered the real
reason why that particular script was so slow.  Zsh executes process
substitutions after forking.  This means that the commands used in process
substitutions never get hashed in the main process so the path is searched
each time.  After adding hash expr to the script zsh become almost as fast
as ksh.  But builtin-only scripts are still much slower than in ksh :-).

Attached is the patch to remove pipe synchronization code.

Zoltan

*** Src/exec.c	1996/08/25 10:32:58	2.85
--- Src/exec.c	1996/08/25 12:05:46
***************
*** 718,731 ****
  		if ((list_pipe || last1) && !list_pipe_child &&
  		    jn->stat & STAT_STOPPED) {
  		    pid_t pid;
- 		    int synch[2];
- 
- 		    pipe(synch);
  
  		    if ((pid = fork()) == -1) {
  			trashzle();
- 			close(synch[0]);
- 			close(synch[1]);
  			putc('\n', stderr);
  			fprintf(stderr, "zsh: job can't be suspended\n");
  			fflush(stderr);
--- 718,726 ----
***************
*** 734,747 ****
  			thisjob = newjob;
  		    }
  		    else if (pid) {
- 			char dummy;
- 
  			list_pipe_pid = pid;
  			nowait = errflag = 1;
  			breaks = loops;
- 			close(synch[1]);
- 			read(synch[0], &dummy, 1);
- 			close(synch[0]);
  			jobtab[list_pipe_job].other = newjob;
  			jobtab[list_pipe_job].stat |= STAT_SUPERJOB;
  			jn->stat |= STAT_SUBJOB | STAT_NOPRINT;
--- 729,737 ----
***************
*** 750,759 ****
  			break;
  		    }
  		    else {
- 			close(synch[0]);
  			entersubsh(Z_ASYNC, 0, 0);
  			setpgrp(0L, mypgrp = jobtab[list_pipe_job].gleader);
- 			close(synch[1]);
  			kill(getpid(), SIGSTOP);
  			list_pipe = 0;
  			list_pipe_child = 1;
--- 740,747 ----
***************
*** 818,843 ****
  	 * shell command, do foo in a subshell and do the     *
  	 * rest of the pipeline in the current shell.         */
  	if (pline->left->type >= CURSH && (how & Z_SYNC)) {
- 	    int synch[2];
- 
- 	    pipe(synch);
  	    if ((pid = fork()) == -1) {
- 		close(synch[0]);
- 		close(synch[1]);
  		zerr("fork failed: %e", NULL, errno);
  	    } else if (pid) {
! 		char dummy, *text;
  
  		text = getjobtext((void *) pline->left);
  		addproc(pid, text);
- 		close(synch[1]);
- 		read(synch[0], &dummy, 1);
- 		close(synch[0]);
  	    } else {
  		zclose(pipes[0]);
- 		close(synch[0]);
  		entersubsh(how, 2, 0);
- 		close(synch[1]);
  		execcmd(pline->left, input, pipes[1], how, 0);
  		_exit(lastval);
  	    }
--- 806,821 ----
  	 * shell command, do foo in a subshell and do the     *
  	 * rest of the pipeline in the current shell.         */
  	if (pline->left->type >= CURSH && (how & Z_SYNC)) {
  	    if ((pid = fork()) == -1) {
  		zerr("fork failed: %e", NULL, errno);
  	    } else if (pid) {
! 		char *text;
  
  		text = getjobtext((void *) pline->left);
  		addproc(pid, text);
  	    } else {
  		zclose(pipes[0]);
  		entersubsh(how, 2, 0);
  		execcmd(pline->left, input, pipes[1], how, 0);
  		_exit(lastval);
  	    }
***************
*** 1411,1430 ****
          sigtrapped[SIGEXIT] || havefiles()))))) {
  
  	pid_t pid;
- 	int synch[2];
- 	char dummy;
  
  	child_block();
- 	pipe(synch);
  
  	if ((pid = zfork()) == -1) {
- 	    close(synch[0]);
- 	    close(synch[1]);
  	    return;
  	} if (pid) {
- 	    close(synch[1]);
- 	    read(synch[0], &dummy, 1);
- 	    close(synch[0]);
  #ifdef HAVE_DEV_FD
  	    closem(2);
  #endif
--- 1389,1400 ----
***************
*** 1442,1450 ****
  	    return;
  	}
  	/* pid == 0 */
- 	close(synch[0]);
  	entersubsh(how, type != SUBSH && !(how & Z_ASYNC) ? 2 : 1, 0);
- 	close(synch[1]);
  	forked = 1;
  	if (sigtrapped[SIGINT] & ZSIG_IGNORED)
  	    holdintr();
--- 1412,1418 ----


  parent reply	other threads:[~1996-08-25 14:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-24 19:59 Zoltan Hidvegi
1996-08-24 21:15 ` Bart Schaefer
1996-08-25  0:12   ` Zoltan Hidvegi
1996-08-25 14:25   ` Zoltan Hidvegi [this message]
1996-08-25 16:22     ` 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=199608251425.QAA25213@hzoli.ppp.cs.elte.hu \
    --to=hzoli@cs.elte.hu \
    --cc=schaefer@nbn.com \
    --cc=zsh-workers@math.gatech.edu \
    /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).