-
-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize lazy loading performance #76
Conversation
zsh-nvm is pretty slow to load even with NVM_LAZY_LOAD=1 due to the presence of a lots of global binaries. I have ~110 global binaries installed, zprof shows that `_zsh_nvm_lazy_load` alone takes 113.23ms, causing noticable delay during shell startup. Further profiling shows that when there are a lot of global binaries, running `basename` on each of them (because `xargs -n1`) is pretty slow, the same goal could be achieved via zsh builtin expansion flags or modifiers and it's much faster. Running `which` in a for loop also has a similar but less significant drawback. After the change zsh-nvm loads in 6.03ms under same conditions. Additionally, added proper quoting to guard against binaries with whitespaces in their name. This has near to zero real-world impact but still, it is the correct thing to do.
I'll be very happy if this is merged. Lazy loading nvm takes >500ms on my machine. |
This works for me with |
This is a really good change! Got almost exactly the same timings as you - 113ms before, 6ms after |
Wow, this is insanely fast now. On my system On a tangential note: I was having a bug (#87 ) sourcing zsh-nvm within an anonymous function, due to the
It'd be great if you could double-check that that makes sense and add the fix to the PR if so. |
I know this is a stale PR and I'm unsure why it was never merged but it allows for significant performance benefits that are very useful in my day-to-day development. Meanwhile I'll use Riatre's fork, if anyone else wants to remove the lag from their terminal startup git clone https://github.com/Riatre/zsh-nvm.git ~/.oh-my-zsh/custom/plugins/zsh-nvm then follow instructions for adding to omz plugins in zshrc |
Sorry guys, I have limited time to spend maintaining my OSS projects these days. I've merged this in, thanks @Riatre! |
This reverts commit a0f0a2c.
zsh-nvm is pretty slow to load even with NVM_LAZY_LOAD=1 due to the
presence of a lots of global binaries. I have ~110 global binaries
installed, zprof shows that
_zsh_nvm_lazy_load
alone takes 113.23ms,causing noticable delay during shell startup.
Further profiling shows that when there are a lot of global binaries,
running
basename
on each of them (becausexargs -n1
) is pretty slow,the same goal could be achieved via zsh builtin expansion flags or
modifiers and it's much faster. Running
which
in a for loop also has asimilar but less significant drawback.
After the change zsh-nvm loads in 6.03ms under same conditions.
Additionally, added proper quoting to guard against binaries with
whitespaces in their name. This has near to zero real-world impact but
still, it is the correct thing to do.
May supersede #75.