jeffreytse/zsh-vi-mode

This plugin is adding a very noticeable amount of delay when opening a new shell session

Open

#316 opened on Apr 21, 2025

View on GitHub
 (22 comments) (0 reactions) (1 assignee)Shell (147 forks)github user discovery
good first issue

Repository metrics

Stars
 (4,364 stars)
PR merge metrics
 (PR metrics pending)

Description

Hi,

I started to use this plugin recently and I noticed my shell sessions are taking quite a bit longer to open up. I've profiled a few things and here's the numbers.

Here are the 4 zsh plugins I use with the profiling features enabled:

zmodload zsh/zprof

. "${XDG_DATA_HOME}/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh"
. "${XDG_DATA_HOME}/zsh-autosuggestions/zsh-autosuggestions.zsh"
. "${XDG_DATA_HOME}/zsh-vi-mode/zsh-vi-mode.plugin.zsh"
. "${XDG_DATA_HOME}/fzf-tab/fzf-tab.plugin.zsh"

zprof

Here's zprof with all 4 plugins enabled:

num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    1          21.57    21.57   74.93%     21.57    21.57   74.93%  zvm_exist_command
 2)    1           4.12     4.12   14.32%      4.12     4.12   14.32%  _zsh_highlight_bind_widgets
 3)    1           2.21     2.21    7.69%      2.21     2.21    7.69%  enable-fzf-tab
 4)    2           0.31     0.15    1.06%      0.31     0.15    1.06%  add-zsh-hook
 5)    1           0.22     0.22    0.78%      0.22     0.22    0.78%  is-at-least
 6)    1           0.16     0.16    0.56%      0.16     0.16    0.56%  (anon) [/home/nick/.local/share/zsh-autosuggestions/zsh-autosuggestions.zsh:460]
 7)    1           0.12     0.12    0.42%      0.12     0.12    0.42%  (anon) [/home/nick/.local/share/fzf-tab/fzf-tab.zsh:398]
 8)    1           0.04     0.04    0.13%      0.04     0.04    0.13%  -fast-highlight-fill-option-variables
 9)    1           0.03     0.03    0.12%      0.03     0.03    0.12%  (anon) [/home/nick/.local/share/fast-syntax-highlighting/fast-highlight:35]

My end to end time is ~140ms:

$ time zsh -i -c exit
zsh -i -c exit  0.03s user 0.02s system 41% cpu 0.140 total

Here's zprof except I commented out this plugin:

num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    1           4.27     4.27   55.94%      4.27     4.27   55.94%  _zsh_highlight_bind_widgets
 2)    1           2.46     2.46   32.19%      2.46     2.46   32.19%  enable-fzf-tab
 3)    2           0.30     0.15    3.93%      0.30     0.15    3.93%  add-zsh-hook
 4)    1           0.24     0.24    3.14%      0.24     0.24    3.14%  is-at-least
 5)    1           0.18     0.18    2.32%      0.18     0.18    2.32%  (anon) [/home/nick/.local/share/zsh-autosuggestions/zsh-autosuggestions.zsh:460]
 6)    1           0.11     0.11    1.48%      0.11     0.11    1.48%  (anon) [/home/nick/.local/share/fzf-tab/fzf-tab.zsh:398]
 7)    1           0.04     0.04    0.51%      0.04     0.04    0.51%  -fast-highlight-fill-option-variables
 8)    1           0.04     0.04    0.48%      0.04     0.04    0.48%  (anon) [/home/nick/.local/share/fast-syntax-highlighting/fast-highlight:35]

My end to end time is ~80ms:

$ time zsh -i -c exit
zsh -i -c exit  0.04s user 0.01s system 59% cpu 0.081 total

I'm not sure if zprof reports milliseconds but it's certainly adding more than 21ms of delay. The end to end time difference is +60ms (140 - 80). It's really noticeable because I have a feeling something else is causing even more of a delay that's not picked up in these tests. It feels like 200-300ms before the prompt is ready.

Any thoughts on how to troubleshoot what's causing this slowdown?

Contributor guide