Loading /etc/bash_completion is slow

Bug #384017 reported by Singpolyma
84
This bug affects 16 people
Affects Status Importance Assigned to Milestone
bash-completion
Invalid
Undecided
Unassigned
bash-completion (Debian)
Fix Released
Unknown
bash-completion (Ubuntu)
Triaged
Medium
Unassigned
Nominated for Lucid by narcelio

Bug Description

Loading /etc/bash_completion takes over 0.5s (usually over 0.6s). While this doesn't seem like much, maybe, it's very annoying for a file that must be sourced in .bashrc. If it could go in .bash_profile, that would be fine, but it seems bash is not designed to work that way for completion rules.

I am on a 1.1Ghz Pentium M, so not ancient h/w. The 0.6s delay on opening a new terminal is very annoying.

Tags: performance
Revision history for this message
Kim Alvefur (zash) wrote :

A way to cache what bash_completion does would be awesome.

Revision history for this message
Kim Alvefur (zash) wrote :

Or, improving and including the on-demand version of bash-completion (forgot what it's called)

Revision history for this message
Kim Alvefur (zash) wrote :

This is what I was thinking of: http://code.google.com/p/bash-completion-lib/
It's not as good as bash-completion, but it's much faster, since it doesn't load all rules at once.

Revision history for this message
AreTee (ryantimmins) wrote :

I also get >0.5s load time on bashrc due to the loading of bash_completion.
I am using Intel(R) Pentium(R) Dual CPU T2330 @ 1.60GHz, 2GB Ram.

Daniel Hahler (blueyed)
Changed in bash-completion (Ubuntu):
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Radosław Bułat (radek-bulat+launchpad) wrote :

What is the progress of this issue? On my computer (core 2 duo, 2.20 GHz) it takes about 1.5-2s to load /etc/bash_completion.

$ time . /etc/bash_completion

real 0m1.656s
user 0m1.290s
sys 0m0.330s

With non warmed up computer (adter rebooting) it could take 2-3x times longer (arrgh).

Revision history for this message
Philip Muškovac (yofel) wrote :

This would most likely be improved once someone takes care of http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=467231

Changed in bash-completion (Debian):
status: Unknown → Confirmed
Revision history for this message
Jason Gunthorpe (jgunthorpe) wrote :

There is more going on here than just loading a lot of completion. Something is weird inside bash, look at the strace of completion loading and you see it is doing a wack of busy work crap like this. The fiddling with FDs looks like it is probably some kind of errant debug feature? This is from maverick with bash 4.1-2ubuntu4. It is annoying that

16:58:30 access("/etc/bash_completion.d/mutt", R_OK) = 0
16:58:30 open("/etc/bash_completion.d/mutt", O_RDONLY) = 3
16:58:30 fstat(3, {st_mode=S_IFREG|0644, st_size=4527, ...}) = 0
16:58:30 read(3, "# mutt completion\n#\n# Mutt doesn"..., 4527) = 4527
16:58:30 close(3) = 0
16:58:30 rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
16:58:30 rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
16:58:30 rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
16:58:30 rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
16:58:30 rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
16:58:30 rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
16:58:30 rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
16:58:30 rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
16:58:30 open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
16:58:30 fcntl(1, F_GETFD) = 0
16:58:30 fcntl(1, F_DUPFD, 10) = 10
16:58:30 fcntl(1, F_GETFD) = 0
16:58:30 fcntl(10, F_SETFD, FD_CLOEXEC) = 0
16:58:30 dup2(3, 1) = 1
16:58:30 close(3) = 0
16:58:30 fcntl(2, F_DUPFD, 10) = 11
16:58:30 fcntl(2, F_GETFD) = 0
16:58:30 fcntl(11, F_SETFD, FD_CLOEXEC) = 0
16:58:30 dup2(1, 2) = 2
16:58:30 stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
16:58:30 stat("/usr/sbin/mutt", 0x7fff6d9e1230) = -1 ENOENT (No such file or dir
16:58:30 stat("/usr/bin/mutt", 0x7fff6d9e1230) = -1 ENOENT (No such file or dire
16:58:30 stat("/sbin/mutt", 0x7fff6d9e1230) = -1 ENOENT (No such file or directo
16:58:30 stat("/bin/mutt", 0x7fff6d9e1230) = -1 ENOENT (No such file or director
16:58:30 stat("/usr/bin/X11/mutt", 0x7fff6d9e1230) = -1 ENOENT (No such file or
16:58:30 stat("/usr/bin/mutt", 0x7fff6d9e1230) = -1 ENOENT (No such file or dire
16:58:30 stat("/usr/local/bin/mutt", 0x7fff6d9e1230) = -1 ENOENT (No such file o
16:58:30 stat("/usr/games/mutt", 0x7fff6d9e1230) = -1 ENOENT (No such file or di
16:58:30 stat("/home/jgg/bin/mutt", 0x7fff6d9e1230) = -1 ENOENT (No such file or
16:58:30 stat("/sbin/mutt", 0x7fff6d9e1230) = -1 ENOENT (No such file or directo
16:58:30 stat("/usr/sbin/mutt", 0x7fff6d9e1230) = -1 ENOENT (No such file or dir
16:58:30 stat("/usr/local/sbin/mutt", 0x7fff6d9e1230) = -1 ENOENT (No such file
16:58:30 write(2, "bash: type: mutt: not found\n", 28) = 28
16:58:30 dup2(11, 2) = 2
16:58:30 fcntl(11, F_GETFD) = 0x1 (flags FD_CLOEXEC)
16:58:30 close(11) = 0
16:58:30 dup2(10, 1) = 1
16:58:30 fcntl(10, F_GETFD) = 0x1 (flags FD_CLOEXEC)
16:58:30 close(10) = 0
16:58:30 rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0

Revision history for this message
Dawid Ciężarkiewicz (dpc-ucore) wrote :

If anybody is interested -- I think I've hacked some nice solution for this. Seems to be working for me (I havn't tested it extensivly).

http://ucore.info/en/2011/03/faster-bash-completion-loading/
https://github.com/dpc/bash_completion

dpc@mutex:~$ time . /etc/bash_completion.orig

real 0m2.360s
user 0m1.510s
sys 0m0.380s
dpc@mutex:~$ time . /etc/bash_completion.new

real 0m0.149s
user 0m0.100s
sys 0m0.010s

Revision history for this message
Dawid Ciężarkiewicz (dpc-ucore) wrote :

I am sorry. I've performed the test for original code with additional links. The real results should be:

dpc@mutex:~$ time . /etc/bash_completion.orig
real 0m0.614s
user 0m0.360s
sys 0m0.120s
dpc@mutex:~$ time . /etc/bash_completion.new
real 0m0.168s
user 0m0.120s
sys 0m0.010s

Revision history for this message
Neal H. Walfield (neal-walfield) wrote :

Loading /etc/bash_completion takes 3 seconds on my Alix-based system (which has an AMD Geode 500 MHz CPU).

Bash completions are loaded in a number of places including via /etc/profile. A non-invasive way to disable this is to add

  BASH_COMPLETION=1

to the start of /etc/profile.

/etc/profile.d/bash_completion.sh will only load /etc/bash_completion if BASH_COMPLETION is the empty string.

If you get an error:

  sed: can't read 1: No such file or directory

Then something else is still trying to load /etc/bash_completion. In my base, this was ~/.bashrc.

Revision history for this message
Gigabit Software (hlavaty-ondrej-gmail) wrote :

Sorry, wrong button... Loading takes long time also in 11.10... And fix from #8 is not working anymore - didn't find out the reason.

Changed in bash-completion:
status: New → Invalid
Changed in bash-completion (Debian):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.