zsh-vi-mode icon indicating copy to clipboard operation
zsh-vi-mode copied to clipboard

Terminal slows down after enabling this plugin

Open sahinakkaya opened this issue 3 years ago • 10 comments

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

  1. Install and enable zsh-prompt-bencmark
  2. Benchmark with zsh-vi-mode enabled
  3. Benchmark with zsh-vi-mode not enabled
  4. 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.

sahinakkaya avatar Apr 28 '21 18:04 sahinakkaya

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

jeffreytse avatar Apr 29 '21 03:04 jeffreytse

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 then set +x I can see a detailed trace. There is a lot of output which contains zsh-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!

sahinakkaya avatar Apr 29 '21 10:04 sahinakkaya

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

jeffreytse avatar Apr 29 '21 10:04 jeffreytse

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

jeffreytse avatar Jul 02 '21 14:07 jeffreytse

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.

sahinakkaya avatar Jul 03 '21 08:07 sahinakkaya

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

jeffreytse avatar Jul 03 '21 08:07 jeffreytse

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.

sahinakkaya avatar Jul 03 '21 08:07 sahinakkaya

Hi @Asocia , sorry for the misunderstanding, did you put the mode option before sourcing this plugin?

jeffreytse avatar Jul 03 '21 08:07 jeffreytse

Yes, it's coming before plugins=(... zsh-vi-mode) line. Actually I tried both case but no luck.

sahinakkaya avatar Jul 03 '21 08:07 sahinakkaya

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.

jeffreytse avatar Jul 03 '21 08:07 jeffreytse