From 7cacf8a4c65d03d64931d8434ecfab0c2cf81e3e Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Mon, 20 Feb 2023 11:04:50 +0900 Subject: [PATCH] Prefer readlink to greadlink rbenv tries to find `greadlink` and then `readlink`. However, there is usually no `greadlink` in Linux. Looking for `greadlink` could be a significant overhead on some environments where `PATH` contains many directories. Ubuntu on WSL2 is just such an environment. Looking for `readlink` before `greadlink` speeds up ruby startup. Before this change: ``` $ time ruby -v ruby 3.3.0dev (2023-02-20T01:33:06Z master 7d5794bad5) [x86_64-linux] real 0m0.532s user 0m0.022s sys 0m0.087s ``` After this change: ``` $ time ruby -v ruby 3.3.0dev (2023-02-20T01:33:06Z master 7d5794bad5) [x86_64-linux] real 0m0.419s user 0m0.042s sys 0m0.055s ``` --- libexec/rbenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index 1241ab6c0..16c40518d 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -41,7 +41,7 @@ export RBENV_DIR canonicalize() { local readlink resolved_path - if readlink="$(type -P greadlink)" || readlink="$(type -P readlink)"; then + if readlink="$(type -P readlink)" || readlink="$(type -P greadlink)"; then # happy path: GNU & BSD readlink, macOS 12.3+ if resolved_path="$("$readlink" -f "$1" 2>/dev/null)"; then printf "%s\n" "$resolved_path"