From a2e8c84683c75d64c6aa1f27e09e85db2d3bc875 Mon Sep 17 00:00:00 2001 From: Nicholas Jackson Date: Wed, 11 Mar 2026 16:35:10 -0700 Subject: [PATCH 1/2] perf: avoid dirname in activation shell hooks Repeated forking of a dirname process can get rather heavy in deep directory structures, especially with distributions that are moving to uutils. This is most problematic for bash, which runs PROMPT_COMMAND for every prompt as opposed to zsh and fish which run the activation check on chdir. Switching to a pure shell calculation of the parent directory makes performance scale much better. On an Intel Core Ultra 7 165H with uutils, the existing dirname solution takes about 30 milliseconds to traverse 10 directories, which is enough to be noticeable. Using the updated pure shell approach reduces the time down to 5-10 milliseconds at a directory depth of 80. --- shell/files/sh_common_hooks.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/files/sh_common_hooks.sh b/shell/files/sh_common_hooks.sh index f2b30d7c..60695a7c 100644 --- a/shell/files/sh_common_hooks.sh +++ b/shell/files/sh_common_hooks.sh @@ -18,7 +18,8 @@ change_hermit_env() { fi return fi - CUR="$(dirname "${CUR}")" + CUR="${CUR%/*}" + CUR="${CUR:-/}" done unset DEACTIVATED_HERMIT if [ -n "${HERMIT_ENV+_}" ]; then type _hermit_deactivate &>/dev/null && _hermit_deactivate; fi From 14e9e069302d1369a3813e59bf56150ec5c24c83 Mon Sep 17 00:00:00 2001 From: Nicholas Jackson Date: Mon, 16 Mar 2026 09:18:18 -0700 Subject: [PATCH 2/2] chore: add clarifying doc comment for dirname removal --- shell/files/sh_common_hooks.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/files/sh_common_hooks.sh b/shell/files/sh_common_hooks.sh index 60695a7c..206733aa 100644 --- a/shell/files/sh_common_hooks.sh +++ b/shell/files/sh_common_hooks.sh @@ -18,6 +18,7 @@ change_hermit_env() { fi return fi + # Set CUR to the next directory up. Avoid using dirname for performance. CUR="${CUR%/*}" CUR="${CUR:-/}" done