-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
Function performance benchmarks #2334
Comments
Awesome, thanks! Once #2317 is landed, I'll take a look at |
Thanks for looking into this! I've spent some more time on this, but due to the fact that I've never worked with a shell script of this size, my methods may be a little crude. Some more interesting data (that I don't pretend to understand):
What I'm probably going to end up doing is adding node to my path and setting It might be interesting to see nvm officially support an option like this (pre-computing some look ups either in a cache or an environment variable). Asking people to set a default version in an environment variable seems reasonable, and possibly more maintainable than optimizing the hell out of the default version look-up logic. |
Nice to see 0.37.0 out!
This is still pretty long. It's come to my attention that the |
Since we are talking performance here, That issue documents that needing to call The current version could be stored in a variable (eg Currently there is no way to get the current node version without checking a bunch of files. |
That's a link to this issue, which issue are you referring to? |
Okay, interesting. I'm not sure how you're testing or what your setup looks like, but for me, (Bash is much faster than zsh by the way. While zsh starts nvm in (If you're wondering why I've given numbers for |
If anyone wants a quick workaround to lower ZSH startup time, and postpone this NVM setup time to the command execution(lazy-loading) you could do something like:
That will call the NVM initialization script, only when you call the nvm_lazy alias. I couldn't seem to make it work with the same name "nvm", because the init-nvm script defines a function(or alias) with that same name. |
@eduhenke init-nvm.sh is AUR-specific, and doesn’t exist for everyone else. |
More on the performance issue with some nvm commands:
Especially the latter, it's a bit too much for |
To improve the performance of |
@ryenus it already uses awk, but I’m sure it could do so more efficiently since I’m not an awk expert. Happy to review a PR. |
Abstract
NVM is the biggest performance bottleneck in loading a new shell for me, taking significantly more time than anything else. I attempted to determine what bits of the
nvm
source code were bottlenecking it. This experiment does not attempt to uncover solutions to these problems, merely narrow down their locations.Environment
I'm using macOS 10.15.6 and zsh 5.7.1. I have only one version of
node
installed throughnvm
,v13.7.0
. The only global packages I have installed arepm2
,npm
, and their 620 unique dependencies. Experiments were conducted in/tmp/nvm
. All that to say, this should fairly closely mimic a fresh install.Methodology
I commented out or made changes to the
nvm.sh
shell script. Then ran it, withThis was repeated 10 times for each change to ensure no flukes. The mode output is reported below. I don't know what
time
actually measures or how accurate it is.Results
0.38s user 0.36s system 108% cpu 0.686 total
380
ms0.21s user 0.31s system 110% cpu 0.471 total
170
msnvm_ensure_version_installed
check [1].0.18s user 0.28s system 112% cpu 0.406 total
30
msnvm_resolve_local_alias
, hardcoded to always return"v13.7.0"
(here)0.08s user 0.10s system 108% cpu 0.166 total
100
msuse
(here specifically)0.05s user 0.06s system 114% cpu 0.097 total
30
msConclusion
By making a few small changes (which do complete break the functionality), the final run-time drops from
380
ms to50
ms. I would consider this theoretical runtime perfectly acceptable, unlike the500
ms that NVM is taking right now. Aside from the current area of focus innpm_config
, which is obviously a great improvement, the next step would be looking at the other areas mentioned. Why doesnvm_resolve_local_alias default
take a100
ms? This is not a question that I am able to answer right now, but seems to be the logical direction to take this issue.Edit: Since 2022 I've been saving 600ms+ per shell start by using https://volta.sh instead of nvm.
The text was updated successfully, but these errors were encountered: