zsh-vi-mode
zsh-vi-mode copied to clipboard
Terminal slows down after enabling this plugin
General infomation
Terminal: Konsole OS: Ubuntu 20.04 ZSH framework: oh-my-zsh ZSH version 5.8 ZVM version 0.8.3
Basic examination
- [x] I have read through the README page
- [x] I have the latest version of zsh-vi-mode
- [x] I have tested with another terminal program
Problem description
Enabling this plugin makes prompt 2.5 times slow. Am I doing something wrong?
Without any plugins
********************************************************************
Prompt Benchmark Results
********************************************************************
Warmup duration 4s
Benchmark duration 2.011s
Benchmarked prompts 112
Time per prompt 17.95ms <-- prompt latency (lower is better)
********************************************************************
Nearly 15 plugins
********************************************************************
Prompt Benchmark Results
********************************************************************
Warmup duration 4s
Benchmark duration 2.001s
Benchmarked prompts 101
Time per prompt 19.81ms <-- prompt latency (lower is better)
********************************************************************
15 other plugins and zsh-vi-mode
********************************************************************
Prompt Benchmark Results
********************************************************************
Warmup duration 4s
Benchmark duration 2.044s
Benchmarked prompts 41
Time per prompt 49.84ms <-- prompt latency (lower is better)
********************************************************************
Here is all my settings related with this plugin:
ZVM_LAZY_KEYBINDINGS=false
ZVM_VI_INSERT_ESCAPE_BINDKEY=kj
plugins=(... zsh-vi-mode)
source $ZSH/oh-my-zsh.sh
# https://github.com/jeffreytse/zsh-vi-mode#execute-extra-commands
function my_bindings() {
# easy bindings instead of ctrl + arrow keys
bindkey '^j' backward-word
bindkey '^f' forward-word
bindkey '^g' autosuggest-accept
bindkey "\e\e" sudo-command-line
}
zvm_after_init_commands+=('[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh')
zvm_after_init_commands+=(my_bindings)
# Always starting with insert mode for each command line
ZVM_LINE_INIT_MODE=$ZVM_MODE_INSERT
ZVM_INSERT_MODE_CURSOR=$ZVM_CURSOR_BLOCK
Reproduction steps
- Install and enable
zsh-prompt-bencmark
- Benchmark with
zsh-vi-mode
enabled - Benchmark with
zsh-vi-mode
not enabled - Compare the results and see this plugin takes too much time
Expected behavior
I expect this plugin to be not take too much time like the other ones.
Hi @Asocia
Firstly, thanks for the detail experience on this plugin :+1:. In fact, this plugin is initialized during the first precmd, it's different from most of other plugins that are initialized during souring the plugin. So the zsh-prompt-bencmark could not detect the prompt time of those plugins. Actually, the initialization time is short now. It will spend no more time on the following precmd, you can refer to the key source code.
Thanks and regards
Yes, as you said it is initialized only once. I disabled precmd hook for this plugin and initialized it myself but result didn't change. I'm curious what makes this plugin slow and if it is possible to make it faster. I really like this plugin and it would be great if this issue can be solved.
Some other examinations:
- When I type
set -x
and thenset +x
I can see a detailed trace. There is a lot of output which containszsh-vi-mode
but I can't interpret it since my knowledge in this area is limited. I just wanted to share so maybe it helps.
Thanks!
Hi @Asocia
There are lots of stuffs need to be done and they are necessary for this plugin running normally. I can add an option to let you set the time of initializating this plugin. And welcome to star this plugin for further updates in the future.
Thanks and regards
Hi @Asocia
Now this plugin has provided an option called ZVM_INIT_MODE
to configure the initialization mode (#113), you can use this snippet ZVM_INIT_MODE=sourcing
for doing the initialization inistantly when this plugin is sourcing.
Thanks and regards
Hi @jeffreytse,
I pulled the recent changes and added ZVM_INIT_MODE=sourcing
to my .zshrc
. I didn't observe any effect on prompt latency. Thanks.
Hi @Asocia
You're welcome and thanks for your checking out. If you get any other issues in the future, welcome to reach me.
Thanks and regards
Uhm, I think you got me wrong. By saying "I didn't observe any effect" I meant that the prompt is still slow as before. It was coming in 34ms and after applying the last change it's still 34ms.
Hi @Asocia , sorry for the misunderstanding, did you put the mode option before sourcing this plugin?
Yes, it's coming before plugins=(... zsh-vi-mode)
line. Actually I tried both case but no luck.
In fact, the zvm_init function will do a lot of neccessary works for the initialization. You can have a look and I will try to do some stuff to further reduce the initialization time in the future, thanks for your attention.