ddworken / hishtory

Your shell history: synced, queryable, and in context
https://hishtory.dev
MIT License
2.43k stars 41 forks source link

hishtory will cause pipeline execution to be particularly time-consuming. #205

Open hongyi-zhao opened 3 months ago

hongyi-zhao commented 3 months ago

If I enable hishtory in ~/.bashrc by adding the following code snippet into it:

if [ -d "$HOME/.hishtory" ] && [ -r "$HOME/.hishtory/config.sh" ]; then
  export PATH="$PATH:$HOME/.hishtory"
  source "$HOME/.hishtory/config.sh"
fi

Then, I noticed that the following simple command would be particularly time-consuming:

werner@MZ73-LM1-000:~$ time echo 1 | tail
1

real    0m1.021s
user    0m0.055s
sys     0m0.016s

If I disable hishtory, the above command will be very fast:

werner@MZ73-LM1-000:~$ time echo 1 | tail
1

real    0m0.014s
user    0m0.010s
sys 0m0.006s

What is the cause of this? Are there some bugs in hishtory that trigger this issue?

Regards, Zhao

hongyi-zhao commented 3 months ago

I got it. The issue reported above is triggered by bash-preexec, which in turn is called by bash-it by default, see here for the related discussion.

In my case, I use bash-it to enhance the UX of bash, so the problem occurs. If I disable the bash-preexec calling from within bash-it as discussed here like the following, the problem will be fixed:

werner@MZ73-LM1-000:~/Public/repo/github.com/bash-it/bash-it.git$ git diff
diff --git a/lib/preexec.bash b/lib/preexec.bash
index 1dbe8899..43d2d4fa 100644
--- a/lib/preexec.bash
+++ b/lib/preexec.bash
@@ -9,7 +9,7 @@
 __bp_delay_install="delayed"

 # shellcheck source-path=SCRIPTDIR/../vendor/github.com/rcaloras/bash-preexec
-source "${BASH_IT?}/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh"
+#source "${BASH_IT?}/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh"

 # Block damanaging user's `$HISTCONTROL`
 function __bp_adjust_histcontrol() { :; }
@@ -22,7 +22,7 @@ function __bp_require_not_readonly() { :; }
 : "${__bp_enable_subshells:=}" # blank

 # Modify `$PROMPT_COMMAND` in finalize hook
-_bash_it_library_finalize_hook+=('__bp_install_after_session_init')
+#_bash_it_library_finalize_hook+=('__bp_install_after_session_init')

 ## Helper functions
 function __check_precmd_conflict() {