zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Possible bug: HASH_CMDS has no observable effect
Date: Sat, 12 Sep 2020 01:35:12 -0700	[thread overview]
Message-ID: <CAH+w=7YDbOLz8Vp9v1tuweX9rGynS19GQ3FDiSryvqX=iz2sNA@mail.gmail.com> (raw)
In-Reply-To: <CAN=4vMrC2QjfxWaPUE9QS9tENBu=7BB=Hmp5rY6SaFahFThq=Q@mail.gmail.com>

On Sat, Sep 12, 2020 at 12:02 AM Roman Perepelitsa
<roman.perepelitsa@gmail.com> wrote:
>
> Do I understand it correctly that this is working as intended? It
> appears to contradict the documentation for HASH_CMDS, which states
> that commands are hashed when they are invoked for the first time.

What it really means is that commands are hashed the first time a path
search finds them.

If you have only HASH_CMDS, then "a path search finds" just the single
command you invoked.  If you tend to be using one, or a few, commands
repeatedly, and never invoke anything else, this is all you need to
avoid path search overhead for commands that exist.  It remains
"expensive" to discover that a command does not exist.

If you also have HASH_DIRS set, then "a path search finds" every entry
in every directory that is searched.  This eliminates the search
overhead for any external command you might use in the future.  In
order to avoid the expense of a useless search when for example you
make a typo, the assumption is made that if the command is not already
in the cache then it must not be in any part of the path that has
previously been searched.  The whole search-and-cache process is
short-circuited.

This really is the intended behavior, because for most people most of
the time new commands do not appear in the path during a shell
session.  It's also the reason that HASH_EXECUTABLES_ONLY eventually
got added, because the "every entry in every directory" part tends to
be too aggressive for some path elements.

Historically, HASH_CMDS predates HASH_DIRS by several years, and the
documentation for the former still uses the wording that encompassed
that state.


  reply	other threads:[~2020-09-12  8:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-11  8:21 Roman Perepelitsa
2020-09-11 14:48 ` Phil Pennock
2020-09-11 15:01   ` Roman Perepelitsa
2020-09-11 16:10     ` Phil Pennock
2020-09-11 16:33       ` Roman Perepelitsa
2020-09-11 21:10         ` Bart Schaefer
2020-09-12  7:02           ` Roman Perepelitsa
2020-09-12  8:35             ` Bart Schaefer [this message]
2020-09-12  8:49               ` Roman Perepelitsa
2020-09-12 20:41                 ` Bart Schaefer
2020-09-12 20:43                   ` Bart Schaefer
2020-09-13  9:31                   ` Roman Perepelitsa
2020-09-13 22:24                     ` 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='CAH+w=7YDbOLz8Vp9v1tuweX9rGynS19GQ3FDiSryvqX=iz2sNA@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=roman.perepelitsa@gmail.com \
    --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).