#764800 spurious function in bash-completion causes >30% performance degradation (and is bug'ed)

#764800#5
Date:
2014-10-11 08:21:27 UTC
From:
To:
There is currently a 'have()' function defined to test if a completion
should be installed based on whether or not they "have" the program.

But it's called for every prog, It sets the path for 1 command to test,
then returns.

This is a slow function:
1) minor perf:  the path isn't set optimally for what it is intended to
do -- it tacks on
"root" paths at the end of whatever PATH already exists... instead, it
should put the main bin (and sbin) directories 1st -- like this:

PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin:$PATH"
---
Note... it should be *saved* at the beginning of the main script,
and *restored* to the user's normal value at the end.  We just want to
ensure likely places to find the commands *first*.

2). BUG: it is using "type <cmd>"  it should use "type -P <cmd>".
type <cmd> will return true for functions and aliases.  If you want
to scan for the program, use -P

3) get rid of the function.  It's one call to 'type'.

use an alias:
   shopt -s expand aliases
   alias have=' >&/dev/null type -P'

Does the same thing saving 32% OVERALL execution time.

I posted details of the timing -- how I did it, and
the scripting to allow for testing perf-changes (not against
untraced code, but other traced versions) to the
bash-completion list, but I wanted to make sure it didn't
fall through the cracks.


The tracing feature works on linux as well as cygwin (slowness
of login on cygwin prompted me to wonder why so made it work
on cygwin (had originally developed it for linux devel/testing).

I can post it here as well if wanted.

To recap -- the have function has a bug (type -P vs. 'type' w/no
arg), AND to fix it, should move to an alias not a function
for over 30% time savings at login.

#764800#10
Date:
2014-10-13 13:52:31 UTC
From:
To:
See comments in bash_completion next to the definition of the
function. Due to its deprecated status it is not likely to be changed
any more, especially in ways that would change its behavior (e.g. the
"type -P" case).

The function is not used by bash-completion itself at all, and 3rd
party completions would be better off migrated to be loaded on demand
-- then they don't need to use this function either (or they can
change to "type" at will if they want to support older bash-completion
versions). More details for 3rd party packages about how to install
completions is in bash-completion's README.