Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

killall command completion is way too slow if there are many user accounts #3996

sarum9in opened this issue Apr 28, 2017 · 1 comment


Copy link

$ fish --version
fish, version 2.4.0

Fish killall autocompletion hangs if there are too many users reported by __fish_print_users (hundreds of thousands). It hangs on the initialization part, problem happens in __make_users_completions, which iterates over the list and performs expensive operations, I suspect it is id which takes 0.1s for each user (most likely because it is network call in my case).
Replacing __fish_print_users with the snippet below, which is essentially fallback behavior of default __fish_print_users plus operator username at the start significantly reduces the number of entries thus making killall autocompletion work again. But this is definitely not a proper solution, just a workaround.

function __fish_print_users --description "Print a list of local users"
    echo $USER
    string match -v -r '^\w*#' < /etc/passwd | cut -d : -f 1

Since __fish_print_users itself works fast one of my ideas would be to check size of the list returned before iterating over it and fallback to "local" version from passwd if it is too big. Draft is below:

function __make_users_completions
	set -l users (__fish_print_users)
	set -l users_size (count $users)
	if math "$users_size>$__fish_killall_max_users"
		set users (__fish_print_local_users)
	for user in $users
		set -l uid (id -u $user)
		# GNU doesn't support UID
		killall --version > /dev/null ^ /dev/null; and set -el uid
		complete -c killall -s u -x -a "$user $uid" -d "Match only processes belonging to $user"
@krader1961 krader1961 added this to the fish-future milestone Apr 29, 2017
Copy link

krader1961 commented Apr 29, 2017

That completion script has a number of inefficiencies. For example, the repeated killall --version invocations should be done exactly once to set a variable that is then checked. I also don't see the point of looking up the UID for a given user name and letting the user choose either the name or ID. Just give the user a list of valid user names and let killall convert it to a UID.

And why is it creating a distinct completion for each user? It should instead just do

complete -c killall -s -u -l user -x -a "(__fish_complete_users)"

@krader1961 krader1961 changed the title killall hangs if there are too many users in the system killall command completion is way too slow if there are many user accounts May 3, 2017
@faho faho closed this as completed in 8814f34 May 4, 2017
@faho faho modified the milestones: 2.6.0, fish-future May 4, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

3 participants