zsh-autocomplete icon indicating copy to clipboard operation
zsh-autocomplete copied to clipboard

zsh-autocomplete is relatively slow on startup (1-2 seconds)

Open tobiasBora opened this issue 1 year ago • 1 comments

  • [X] I have carefully read all of the instructions in this issue template.
  • [X] I have carried them out to the letter.

Environment

> print $VENDOR $OSTYPE $SHELL $ZSH_ARGZERO $ZSH_PATCHLEVEL
pc linux-gnu /run/current-system/sw/bin/bash zsh zsh-5.9-0-g73d3173
> print -l $_autocomplete__funcfiletrace

> git -C ~zsh-autocomplete log --oneline -n1
fatal: ni ceci ni aucun de ses répertoires parents n'est un dépôt git : .git
# Note that I install it from 4c363ff553be227db90842d7481fd6e02de8703c with home manager
  • Operating system: NixOs
  • Terminal emulator: Konsole

Steps to reproduce

zsh-autocomplete is relatively slow on startup (1-2 seconds, which is not huge… but not small either especially when many scripts are loaded and when the system is overloaded, in which case it can be much more)

It's hard to point exactly to a setup that is slow as the time seems to increase in more complex setups. But when we run the most basic config zsh-autocomplete already takes maybe 1 second to start

cd $(mktemp -d)
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
> .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
source ~/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF
env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d

Then if we run it with zsh-powerlevel10k then it is slightly slower, maybe 2 seconds:

Peek 07-09-2022 02-05

Note that if we disable this script the loading time is basically not noticeable:

Peek 07-09-2022 02-09

To create these more complex setups, I actually used this config by home manager (for the ./p10k-config/p10k.zsh file you can put any style you like created with p10k configure, if you want I can give mine but these files are rather lengthy so I guess it's better not to paste them here)

{ config, lib, pkgs, ... }:
let
  # load the configuration that we was generated the first
  # time zsh were loaded with powerlevel enabled.
  # Make sure to comment this part if you want to run
  # again 'p10k configure' and to copy the generated file
  # $ mv ~/.p10k.zsh p10k-config/p10k.zsh
  configThemeNormal = ./p10k-config/p10k.zsh;
  configThemeTTY = ./p10k-config/p10k_tty.zsh;
in
{
  fonts.fontconfig.enable = true;
  home.packages = with pkgs; [
    # Meslo Nerd Font patched for Powerlevel10k
    # Restart Konsole and configure it (profile) to choose MesloLGS NF
    meslo-lgs-nf
    # For fuzzy filter in cd
    # https://github.com/junegunn/fzf
    fzf
    any-nix-shell
    zsh
  ];
  programs.direnv.enableZshIntegration = true;
  programs.zsh = {
    enable = true;
    # enableAutosuggestions = true;
    enableCompletion = true;
    enableSyntaxHighlighting = true;
    enableVteIntegration = true;
    defaultKeymap = "emacs";
    initExtra = ''
      # By default backward deleting a word would consider / as a regular
      # word. Now this problem is gone with this option, see also
      # https://stackoverflow.com/questions/444951/zsh-stop-backward-kill-word-on-directory-delimiter
      autoload -U select-word-style
      select-word-style bash

      # Ctrl-arrows fail in konsole
      # https://unix.stackexchange.com/questions/58870/ctrl-left-right-arrow-keys-issue
      # urxvt/rxvt-unicode (and maybe others):
      bindkey "^[Od" backward-word
      bindkey "^[Oc" forward-word
      # alacritty, konsole, terminator, xterm (and maybe others):
      bindkey "^[[1;5D" backward-word
      bindkey "^[[1;5C" forward-word
      # to find the proper char just type cat and type your char!
      bindkey "^[[3~" delete-char
      # By default, only alt-backspace deletes a word, now we can also use
      # ctrl instead of Alt
      bindkey "^H" backward-kill-word

      if zmodload zsh/terminfo && (( terminfo[colors] >= 256 )); then
        [[ ! -f ${configThemeNormal} ]] || source ${configThemeNormal}
      else
        [[ ! -f ${configThemeTTY} ]] || source ${configThemeTTY}
      fi

      any-nix-shell zsh --info-right | source /dev/stdin
    '';

    # https://github.com/marlonrichert/zsh-autocomplete
    # COMMENT THE NEXT 11 LINES TO SEE THE QUICK VERSION    
    completionInit = let
      autoComplete = pkgs.fetchFromGitHub {
        owner = "marlonrichert";
        repo = "zsh-autocomplete";
        rev = "4c363ff553be227db90842d7481fd6e02de8703c";
        sha256 = "sha256-3hRRrTpRtVrQdc2rTO67Sn1SJ5nPop9liTJfu3qRYHs=";
      };
    in ''
      source ${autoComplete}/zsh-autocomplete.plugin.zsh
    '';
    
    plugins = [
      {
        # A prompt will appear the first time to configure it properly
        # make sure to select MesloLGS NF as the font in Konsole
        name = "powerlevel10k";
        src = pkgs.zsh-powerlevel10k;
        file = "share/zsh-powerlevel10k/powerlevel10k.zsh-theme";
      }
    ];
  };
}

  • [X] I have run the code block above to create a test environment.
  • [X] I have reproduced my problem in this environment in the most minimal way possible.
  • [X] I have copy-pasted my entire test session into the same code block.

tobiasBora avatar Sep 07 '22 00:09 tobiasBora

I actually used this config by home manager

I have no idea what kind of config that is.

Can you please use the setup I provided in the bug report template to create a minimal, reproducible test case. Thanks!

marlonrichert avatar Sep 08 '22 04:09 marlonrichert

Closing, as I haven't heard back from @tobiasBora.

marlonrichert avatar Oct 24 '22 14:10 marlonrichert