From 89d4e8a0e0e16a4afd7c834d28d1ba21b81a8182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 15 Oct 2014 04:05:41 +0200 Subject: [PATCH] Speed up rehash process when there are many Ruby versions On my system that has 25 versions under rbenv, this speeds up rehash almost 3-fold: - before: 391 ms - after: 134 ms This is achieved by removing duplicate names of executables before registering them as shims. Since most Rubies will share a lot of the same executable names ("ruby", "rake", "bundle", ...), this is a considerable reduction in number of shims registered. --- libexec/rbenv-rehash | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index d89af7fa..df221e65 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -79,6 +79,14 @@ remove_outdated_shims() { done } +# List basenames of executables for every Ruby version +list_executable_names() { + local file + for file in "$RBENV_ROOT"/versions/*/bin/*; do + echo "${file##*/}" + done +} + # The basename of each argument passed to `make_shims` will be # registered for installation as a shim. In this way, plugins may call # `make_shims` with a glob to register many shims at once. @@ -136,7 +144,7 @@ shopt -s nullglob # executables. create_prototype_shim remove_outdated_shims -make_shims ../versions/*/bin/* +make_shims $(list_executable_names | sort -u) # Allow plugins to register shims.