command-not-found slow for its task
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
command-not-found (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: command-not-found
Considering command-not-found has a relatively simple job. It seems that it is horribly over-engineered for its task. And as such, we have runtimes such as this:
$ time sl
The program 'sl' is currently not installed. You can install it by typing:
sudo apt-get install sl
real 0m1.715s
user 0m0.680s
sys 0m0.228s
$ time sl
The program 'sl' is currently not installed. You can install it by typing:
sudo apt-get install sl
real 0m0.759s
user 0m0.592s
sys 0m0.116s
A little over a year ago I wrote a replacement script, that I've numerously lost, found, updated and forgotten about. It is about 250 LOC, and kept with one thing in mind, KISS. What surprises me most though is not the simplicity in comparison, but that it is 14x faster at executing it's job.
That script can be found here: http://
And this is how well it runs in comparison.
$ time sl
The program 'sl' is currently not installed. You can install it by typing:
sudo apt-get install sl
real 0m0.079s
user 0m0.036s
sys 0m0.016s
$ time sl
The program 'sl' is currently not installed. You can install it by typing:
sudo apt-get install sl
real 0m0.062s
user 0m0.044s
sys 0m0.016s
You would be forgiven in thinking I used a compiled application to get such low times, but it is not, I tell you that now.
So the ultimate question is, why punish users? I think some act needs to be gotten together to clamp down on the speed demons in this application. As IMO, it is in an unacceptable state.
Regards
ProblemType: Bug
DistroRelease: Ubuntu 10.04
Package: command-not-found 0.2.40ubuntu5
ProcVersionSign
Uname: Linux 2.6.32-22-generic i686
Architecture: i386
Date: Thu Jun 24 22:33:33 2010
PackageArchitec
ProcEnviron:
LANG=en_GB.utf8
SHELL=/bin/bash
SourcePackage: command-not-found
Changed in command-not-found (Ubuntu): | |
status: | New → Confirmed |
Feel free to help me out. The only issue why this app is slow is python startup time. A rewrite in C would make it much more responsive. NB: The app is _fast_ but not _responsive_.
More than a year ago I did an experiment with c-n-f running as a daemon with a trimmed-down C program talking to it over dbus. The initial response was roughly identical to what c-n-f does today. Each subsequent response was instant (on a very slow atom laptop with spinning disk). I did not finish that design but I think the idea is sound.
There are three things taking time in c-n-f:
1) The start up time of the environment (currently the only really slow thing)
2) The query, this is actually very fast using binary database optimized for lookups. It actually answers 10s or even 100s queries each time you miss-type a command as it searches for similar command to offer typo suggestions. I don't see the need to optimize this much but one possible solution would be to add a cache for things that people often miss-type to save on the "spellchecker" lookups.
3) The time it takes to format and print the message, this is very fast and I don't see the need to change that.