Giter VIP home page Giter VIP logo

Comments (8)

tconroy avatar tconroy commented on August 17, 2024 2

Yes I think so -- it's much faster now. Thanks for your help!

from zgenom.

tconroy avatar tconroy commented on August 17, 2024 1

Thanks for the thoughtful, detailed reply @jandamm ! Lots of great tips.

I've been making some changes the last few days to try and optimize. I ended up doing a fresh install to get away from the .zgen naming and embrace .zgenom.

Also followed your advice, including removing the ohmyzsh base, and it seems things are noticeably faster now (although still not as fast as I want, trying to get to 100ms or lower):

-----------------------------------------------------------------------------------
 1)    1          97.38    97.38   59.64%     97.33    97.33   59.61%  _zsh_nvm_lazy_load
 2)    2         140.37    70.19   85.96%     33.78    16.89   20.69%  zgenom
 3)    2          13.97     6.98    8.55%     13.97     6.98    8.55%  compaudit
 4)    1          22.92    22.92   14.04%      8.95     8.95    5.48%  compinit
 5)    1           4.35     4.35    2.66%      4.35     4.35    2.66%  _add_identities
 6)    1           0.94     0.94    0.58%      0.93     0.93    0.57%  _zsh_highlight__function_callable_p
 7)   22           0.84     0.04    0.51%      0.84     0.04    0.51%  compdef
 8)    1           0.75     0.75    0.46%      0.71     0.71    0.43%  _zsh_highlight_load_highlighters
 9)    3           0.60     0.20    0.37%      0.58     0.19    0.36%  add-zle-hook-widget
10)    8           0.57     0.07    0.35%      0.57     0.07    0.35%  is-at-least
11)    1           0.57     0.57    0.35%      0.49     0.49    0.30%  _zsh_nvm_completion
12)    1           0.33     0.33    0.20%      0.33     0.33    0.20%  _start_agent
13)    5           0.26     0.05    0.16%      0.26     0.05    0.16%  add-zsh-hook
14)    2           0.20     0.10    0.12%      0.07     0.04    0.04%  zgenom-autoupdate
15)    1           0.05     0.05    0.03%      0.05     0.05    0.03%  _zsh_nvm_has
16)    1           0.07     0.07    0.04%      0.03     0.03    0.02%  complete
17)    1           0.02     0.02    0.01%      0.02     0.02    0.01%  (anon) [/usr/share/zsh/5.9/functions/add-zle-hook-widget:28]
18)    1           0.01     0.01    0.01%      0.01     0.01    0.01%  _zsh_highlight__is_function_p
19)    1           0.01     0.01    0.01%      0.01     0.01    0.01%  bashcompinit
20)    1           0.00     0.00    0.00%      0.00     0.00    0.00%  _zsh_highlight_bind_widgets

-----------------------------------------------------------------------------------

So compdef is much improved now (1653 calls down to 22!). zgenom (and interestingly, _zsh_nvm_lazy_load) seem to be the slow parts now 🤔 not entirely sure if I can optimize these any further.

Here's my current config, FWIW:

# if any of these files are modified, re-save zgenom
ZGEN_RESET_ON_CHANGE=(
  "${HOME}/.zshrc"
  "${HOME}/.shell_exports"
  "${HOME}/.shell_aliases"
  "${HOME}/.shell_functions"
  "${HOME}/.shell_config"
  "${HOME}/.zsh.local"
)

# Check if zgenom exists -- if not, clone it.
if [ ! -d "${HOME}/.zgenom" ]; then
  printf "${HOME}/.zgenom doesnt exist. Installing zgenom..."
  git clone ssh://[email protected]/jandamm/zgenom.git "${HOME}/.zgenom"
fi

# load zgen & autoupdate every week (no increase to startup time)
source "${HOME}/.zgenom/zgenom.zsh"
zgenom autoupdate

# If zgenom init script doesn't exist, generate it
if ! zgenom saved; then
  echo "Creating a zgenom save..."
  zgenom compdef
  # early to ensure other plugins have access
  zgenom load lukechilds/zsh-nvm

  # zgenom ohmyzsh
  zgenom ohmyzsh plugins/brew
  # zgenom ohmyzsh plugins/docker
  zgenom ohmyzsh plugins/docker-compose
  zgenom ohmyzsh plugins/gem
  zgenom ohmyzsh plugins/git
  zgenom ohmyzsh plugins/git-extras
  zgenom ohmyzsh plugins/git-flow
  zgenom ohmyzsh plugins/node
  zgenom ohmyzsh plugins/npm
  zgenom ohmyzsh plugins/pip
  zgenom ohmyzsh plugins/ssh-agent
  zgenom ohmyzsh plugins/sudo
  zgenom ohmyzsh plugins/z
  zgenom ohmyzsh themes/refined

  # Install ohmyzsh osx plugin if on macOS
  [[ "$(uname -s)" = Darwin ]] && zgenom ohmyzsh plugins/macos

  zgenom load zsh-users/zsh-syntax-highlighting
  zgenom load zsh-users/zsh-completions
  zgenom load zpm-zsh/ls

  # save to init script
  zgenom save 
  zgenom compile "${ZDOTDIR:-${HOME}}/.zshrc"
fi

Thanks again for your help! ❤️

from zgenom.

jandamm avatar jandamm commented on August 17, 2024 1

You can check my config. I've setup zgenom with p10k.
https://github.com/jandamm/dotfiles/blob/416e7b2507f80f73202ab8fa218ae10c1c2f9dd3/zsh/.config/zsh/init.zsh#L19

Otherwise for "adding code to the init.zsh" you can have a look at the eval extension for zgenom. It allows you to run a command or use heredoc to create an instant plugin for it. But this shouldn't be needed for powerlevel10k.

from zgenom.

tconroy avatar tconroy commented on August 17, 2024

additional data point, if I comment out everything starting at zgen oh-my-zsh and ending at zgen save, then the performance is fixed -- but obviously I'd prefer to have my plugins 😓

num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    2          17.21     8.60   52.74%     17.21     8.60   52.74%  compinit
 2)    1           9.76     9.76   29.92%      9.76     9.76   29.92%  nvm_supports_source_options
 3)    1          14.35    14.35   43.99%      5.47     5.47   16.76%  zgen-init
 4)    1           0.06     0.06    0.20%      0.06     0.06    0.20%  compdef
 5)    1           0.06     0.06    0.19%      0.06     0.06    0.19%  nvm_has
 6)    1           9.83     9.83   30.12%      0.05     0.05    0.15%  nvm_process_parameters
 7)    1           0.02     0.02    0.05%      0.02     0.02    0.05%  nvm_auto

-----------------------------------------------------------------------------------

from zgenom.

jandamm avatar jandamm commented on August 17, 2024

Hey @tconroy,

thanks for migrating and reporting this issue.
I've had a similar report a few months ago (see #147).

As stated there it's most likely an issue/something added in oh my zsh.

Since zgen-init is actually just sourcing the init.zsh it is expected to be "slow". Compinit is slow since you load many completions (1653 calls to compdef)
You could try to just remove zgen oh-my-zsh this is loading the ohmyzsh base which you may not need. Most of the time it's fine to just load a few libs (e.g. zgenom ohmyzsh lib/git) from ohmyzsh. If you run into issues with compdef not being defined you can add zgenom compdef before loading ohmyzsh. This will allow plugins to define completions and will replay them when it's appropriate to do so.

You're using the feature to observe changes of a file to update plugins. I haven't gotten around to update that code to be fast, so this is currently still a little hit on the startup time (not slower than zgen but it could be nearly instant)

Apart from that, you can simplify your config by using zgenom saved instead of checking for the init file yourself. This will also source the file if it exists. (See example: https://github.com/jandamm/zgenom#example-zshrc)

Compiling your init.zsh isn't needed anymore. Zgenom does that for you.

Also please don't use unixorn/autoupdate-zgen. This is now builtin and way faster. (See https://github.com/jandamm/zgenom#run-updates-automatically)

Feel free to ask more questions.
I don't think it's an issue in zgenom but if it is one I'd like to fix it.

from zgenom.

jandamm avatar jandamm commented on August 17, 2024

If you want to test the startup penalty of zgenom itself you can comment out all source commands in the init file and then test again. But you shouldn't find much time spent there.
The time of sourcing all plugins is attributed to the zgenom function.

I'd guess that nvm is now longer since you added zgenom load lukechilds/zsh-nvm.

In your earlier config you autoupdated less often (30/60d)you can change that with zgenom as well. zgenom autoupdate --self 60 --plugin 30
But at least in my opinion once a week is fine since it just runs in the background 🤷‍♂️

from zgenom.

tconroy avatar tconroy commented on August 17, 2024

Thanks! Made a few more changes:

  • got rid of nvm and the plugin entirely -- instead I've switched over to fnm, which is a node version manager built in rust and doesn't have the same initialization costs as NVM. That considerably sped things up.
  • dropped the zsh theme in favor of powerlevel10k. This comes bundled with "instant prompt" which seems to have some magic that made my startup noticeably faster.

Now I am just about where I want to be, my init time is under 100ms (or at least its fast enough that I cannot tell). 🎉

The only annoying bit is I couldn't figure out a way to load external themes with zgenom natively -- so I needed to make the following changes to my config :/ any suggestions for how this could be done better / leverage zgenom for this?

function command_exists() {
  command -v "$@" 1>/dev/null 2>&1;
}

# Load the shell dotfiles, if they exist
for file in $HOME/.{shell_exports,shell_config,shell_aliases,shell_functions,zsh.local}; do
  [ -r "$file" ] && [ -f "$file" ] && source "$file";
done;
unset file;

# auto-load bash completions from brew
# https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh
if type brew &>/dev/null
then
  FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"

  autoload -Uz compinit -C
  compinit -C
fi

##############################################################################
# ZGENOM START
##############################################################################
# if any of these files are modified, re-save zgenom
ZGEN_RESET_ON_CHANGE=(
  "${HOME}/.zshrc"
  "${HOME}/.shell_exports"
  "${HOME}/.shell_aliases"
  "${HOME}/.shell_functions"
  "${HOME}/.shell_config"
  "${HOME}/.zsh.local"
)

# Check if zgenom exists -- if not, clone it.
if [ ! -d "${HOME}/.zgenom" ]; then
  printf "${HOME}/.zgenom doesnt exist. Installing zgenom..."
  git clone ssh://[email protected]/jandamm/zgenom.git "${HOME}/.zgenom"
fi

# load zgen & autoupdate every week (no increase to startup time)
source "${HOME}/.zgenom/zgenom.zsh"
zgenom autoupdate

# If zgenom init script doesn't exist, generate it
if ! zgenom saved; then
  echo "Creating a zgenom save..."

+   # Activate powerlevel10k instant prompt. zgenom is making this a bit difficult 
+   () {
+     mkdir -p -- $1
+     {
+       print -r -- 'if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then'
+       print -r -- '  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"'
+       print -r -- 'fi'
+     } >$1/init.zsh
+     zgenom load p10k-instant-prompt
+   } "$(zgenom api clone_dir p10k-instant-prompt)"

  zgenom ohmyzsh --completion plugins/fnm
  zgenom ohmyzsh --completion plugins/docker-compose
  zgenom ohmyzsh --completion plugins/docker
  zgenom ohmyzsh plugins/brew
  zgenom ohmyzsh plugins/gem
  zgenom ohmyzsh plugins/git
  zgenom ohmyzsh plugins/git-extras
  zgenom ohmyzsh plugins/git-flow
  zgenom ohmyzsh plugins/node
  zgenom ohmyzsh plugins/npm
  zgenom ohmyzsh plugins/pip
  zgenom ohmyzsh plugins/ssh-agent
  zgenom ohmyzsh plugins/sudo
  zgenom ohmyzsh plugins/z
- zgenom ohmyzsh themes/refined

  # Install ohmyzsh osx plugin if on macOS
  [[ "$(uname -s)" = Darwin ]] && zgenom ohmyzsh plugins/macos

  zgenom load mroth/evalcache
  zgenom load zdharma-continuum/fast-syntax-highlighting
  zgenom load zsh-users/zsh-completions
  zgenom load zsh-users/zsh-autosuggestions
  zgenom load zsh-users/zsh-autocomplete
  zgenom load zpm-zsh/ls
+  zgenom load romkatv/powerlevel10k

  # clear evalcache. note: not using provided `_evalcache_clear` method because it enforces `-i`
  # confirmation flag.
  rm "$ZSH_EVALCACHE_DIR"/init-*.sh

  # save to init script
  zgenom save 
  zgenom compile "${ZDOTDIR:-${HOME}}/.zshrc"
fi
##############################################################################
# /ZGEN END
##############################################################################  
+ # Load powerlevel10k config.
+ [[ ! -e ~/.p10k.zsh ]] || source ~/.p10k.zsh
+ # Load powerlevel10k itself. There must be a way to load third-party themes
+ # with zgenom but I failed to find how.
+ autoload -Uz prompt_powerlevel10k_setup && prompt_powerlevel10k_setup

if command_exists pyenv; then
  # auto-load pyenv - https://github.com/pyenv/pyenv/tree/master?tab=readme-ov-file#set-up-your-shell-environment-for-pyenv
  _evalcache pyenv init - 
fi

if command_exists fnm; then
  # auto-load fnm - https://github.com/Schniz/fnm#shell-setup
  _evalcache fnm env --use-on-cd 
fi

from zgenom.

jandamm avatar jandamm commented on August 17, 2024

Did you figure it out?
Can I close this issue?

from zgenom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.