[Bash-completion-devel] Bug#764800: spurious function in bash-completion causes >30% performance degradation (and is bug'ed)

Linda A. Walsh bash at tlinx.org
Sat Oct 11 08:21:27 UTC 2014


Package: bash-completion
Version: 2.1-3.1.2 being used in bash 4.2-68.
Severity: minor

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.



More information about the Bash-completion-devel mailing list