prezto icon indicating copy to clipboard operation
prezto copied to clipboard

Slow plugin initialisation of completion and autosuggestions when loading prezto from the nix store (Nix-specific)

Open NickHu opened this issue 4 years ago • 0 comments

Description

I was trying to debug my slow zsh initialisation time, which I have installed via nix, and on a whim I decided to copy prezto from the nix store to my home directory. To my exasperation, this actually sped things up dramatically, even though it didn't cross filesystems! I've narrowed it down to some interaction between the completion and autosuggestion plugins. I'm using btrfs on a brand-new SSD, in case it matters.

The only reasonable explanation I can think of is that /nix/store has hundreds of directories under it and this is somehow causing slow initialisation.

Expected behavior

Zsh takes the same amount of time to initialise

Actual behavior

Zsh takes much longer to initialise when prezto is installed under /nix/store, compared to ~, even if both are on the same filesystem

Steps to Reproduce

  1. install prezto via nix: nix-build '<nixpkgs>' -A zsh-prezto
  2. copy it to the home directory: cp -r $(nix-build '<nixpkgs>' -A zsh-prezto) ~/prezto
  3. create a minimal .zshrc and .zpreztorc:
echo "source $(nix-build '<nixpkgs>' -A zsh-prezto)/init.zsh" > ~/.zshrc
echo "zstyle ':prezto:load' pmodule 'completion' 'autosuggestions'" > ~/.zpreztorc
  1. Measure initialisation time: time zsh -i -c exit

I get:

~ ❯ time zsh -i -c exit                                                         ~
zsh -i -c exit  0.16s user 0.13s system 99% cpu 0.292 total
~ ❯ time zsh -i -c exit                                                         ~
zsh -i -c exit  0.17s user 0.13s system 99% cpu 0.300 total
~ ❯ time zsh -i -c exit                                                         ~
zsh -i -c exit  0.16s user 0.14s system 99% cpu 0.301 total
  1. change zshrc to load prezto from home directory instead: rm -f ~/.zshrc && echo "source $HOME/prezto/init.zsh" > ~/.zshrc
  2. Measure initialisation time: time zsh -i -c exit

I get:

~ ❯ time zsh -i -c exit                                                         ~
zsh -i -c exit  0.06s user 0.02s system 98% cpu 0.076 total
~ ❯ time zsh -i -c exit                                                         ~
zsh -i -c exit  0.06s user 0.01s system 99% cpu 0.078 total
~ ❯ time zsh -i -c exit                                                         ~
zsh -i -c exit  0.06s user 0.01s system 98% cpu 0.077 total

With this minimal example, there is a difference of around 230ms load time, but with my full zshrc and prezto configuration the discrepancy is more like 800ms.

Versions

  • Prezto commit: tested on both 1f4601e44c989b90dc7314b151891fa60a101251 (the current version of prezto in nixpkgs) and 13c61bae30c3a8cf610623c094f2aa0a95fbf035 (pending update in nixpkgs https://github.com/NixOS/nixpkgs/pull/88036)
  • ZSH version: zsh 5.8 (x86_64-pc-linux-gnu)
  • OS information: NixOS 20.09.git.617cd4eb14c (Nightingale)

NickHu avatar May 20 '20 00:05 NickHu