zsh-users
 help / color / mirror / code / Atom feed
From: Greg Klanderman <gak@klanderman.net>
To: zsh-users@zsh.org
Subject: Re: [Feature suggestion] (user configurable) timeout for generating completion lists
Date: Wed, 29 Jan 2014 11:29:24 -0500	[thread overview]
Message-ID: <87eh3q3g63.fsf@lwm.klanderman.net> (raw)
In-Reply-To: <140125124934.ZM23767@torch.brasslantern.com> (Bart Schaefer's message of "Sat, 25 Jan 2014 12:49:34 -0800")

>>>>> On January 25, 2014 Bart Schaefer <schaefer@brasslantern.com> wrote:

> On Jan 24,  9:46am, Greg Klanderman wrote:
> }
> } For slow completion due to calling out to a separate process for
> } completions (_git comes to mind) if that is not currently
> } interruptible it seems like there might be some hope of adding a
> } timeout or ensuring C-c will interrupt.

> This is the thing I had a hard time reproducing.  Even if I force
> the completion function to be very busy with a loop, I can interrupt
> it.  (Oddly the value of $? is always 0 in _main_complete after I
> hit ^C, so I can't detect the signal and issue a message.)

Did you try a busy completion function, or external process?

Great if this case works well.. I didn't test it and haven't noticed a
problem, but I don't think I commonly use any completion that calls
out to an external program and is slow.  I know some have complained
about the git completion with big repos, but I'm fairly new to git and
haven't found a case that's slow yet.  If someone has an example, let
me know..

> } The biggest problem I've had with completion being unresponsive was
> } due to automounts at work (currently have ~53k under a handful of
> } mount points).  Using the fake-files zstyle mostly works until
> } completion tries to stat all those automounts

> I think this is analogous to the situation that started this thread.

Similar issue, though my case will only come up if you go to the
trouble of setting up a fake-files zstyle with the automount points.
The slowness is from stat'ing 53k automounts, and it does not seem to
be interruptible with C-c.  Also if you hit tab after "/home/" it ends
up actually mounting as many of the automounts under /home as it can
before you manage to kill the shell from another window, which is
non-ideal.

In the original post it seemed that the slow call was probably reading
a large directory on a slow NFS mount.

> } to determine the file type in order to append a '/' or ' '.

> ... which is difficult to do if there's an external program doing the
> stat.  Not impossible, but it means passing a lot of structured data
> through a pipe, which might slow down more common cases.

The protobuf library works well for that sort of thing though I'm not
sure if it has straight C bindings.

> (Maybe this is why Meino wants "find -print0 -ls". :-> )

> } So locally I run zsh with a
> } small patch (to ztat()) that uses a shell variable to configure
> } automount roots under which all immediate entries are assumed to be
> } directories without stat'ing.  Works great, though I don't think
> } several years ago you were willing to incorporate that into zsh.

> Doesn't sound terrible,

I'll attach the patch below, if you'd be willing to incorporate
something like it let me know, I'd certainly prefer to have it part of
zsh.  I would add documentation of course.

It gets used like this:

completion_nostat_dirs=(/home /net)
zstyle ':completion:*' fake-files '/home:foo bar baz' '/net:aaa bbb ccc' ...

> but I don't think it would solve the original
> problem, which if I'm right is that NFS listing is big/slow after the
> mount is already completed.

Correct.

Greg

Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.122
diff -u -r1.122 init.c
--- Src/init.c	5 Jan 2012 20:01:25 -0000	1.122
+++ Src/init.c	9 Jan 2012 20:09:36 -0000
@@ -827,6 +827,8 @@
     modulestab = newmoduletable(17, "modules");
     linkedmodules = znewlinklist();
 
+    completion_nostat_dirs = mkarray(NULL);
+
     /* Set default prompts */
     if(unset(INTERACTIVE)) {
 	prompt = ztrdup("");
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.177
diff -u -r1.177 params.c
--- Src/params.c	7 Jan 2012 23:21:00 -0000	1.177
+++ Src/params.c	9 Jan 2012 20:09:36 -0000
@@ -104,6 +104,10 @@
      zoptind,		/* $OPTIND      */
      shlvl;		/* $SHLVL       */
 
+/**/
+mod_export
+char **completion_nostat_dirs;
+
 /* $histchars */
  
 /**/
@@ -356,6 +360,8 @@
 IPDEF9F("*", &pparams, NULL, PM_ARRAY|PM_SPECIAL|PM_DONTIMPORT|PM_READONLY),
 IPDEF9F("@", &pparams, NULL, PM_ARRAY|PM_SPECIAL|PM_DONTIMPORT|PM_READONLY),
 
+IPDEF9("completion_nostat_dirs", &completion_nostat_dirs, NULL),
+
 /*
  * This empty row indicates the end of parameters available in
  * all emulations.
Index: Src/Zle/compresult.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compresult.c,v
retrieving revision 1.82
diff -u -r1.82 compresult.c
--- Src/Zle/compresult.c	14 May 2011 00:07:42 -0000	1.82
+++ Src/Zle/compresult.c	9 Jan 2012 20:09:37 -0000
@@ -868,11 +868,25 @@
 ztat(char *nam, struct stat *buf, int ls)
 {
     int ret;
+    char **pp;
 
     nam = unmeta(nam);
     if (!nam)
 	return -1;
 
+    for (pp = completion_nostat_dirs; *pp; pp++) {
+        int len = strlen(*pp);
+
+        if ((*pp)[len-1] == '/')
+            len--;
+
+        if (strncmp(nam, *pp, len) == 0 && nam[len] == '/' && strchr(nam+len+1, '/') == NULL) {
+            memset(buf, 0, sizeof(*buf));
+            buf->st_mode = S_IFDIR; /* pretend it's a directory */
+            return 0;
+        }
+    }
+
     if ((ret = ls ? lstat(nam, buf) : stat(nam, buf))) {
 	char *p, *q;
 


  reply	other threads:[~2014-01-29 16:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-20  7:13 Arseny Tolmachev
2014-01-22  8:04 ` Bart Schaefer
2014-01-23 12:04   ` Nikolai Weibull
2014-01-24  1:16     ` Bart Schaefer
2014-01-24  9:00       ` Nikolai Weibull
2014-01-25 20:09         ` _git and partial completion, again Bart Schaefer
2014-01-24 14:46       ` [Feature suggestion] (user configurable) timeout for generating completion lists Greg Klanderman
2014-01-25 20:49         ` Bart Schaefer
2014-01-29 16:29           ` Greg Klanderman [this message]
2014-02-25 15:35           ` Greg Klanderman
2014-01-22 13:51 ` Shawn Wilson

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=87eh3q3g63.fsf@lwm.klanderman.net \
    --to=gak@klanderman.net \
    --cc=zsh-users@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).