-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Performance: nvm use default
slow, slows down shell startup (nvm.sh)
#703
Comments
OK, I think I identified most of the places that cause slowdown - got it down to .05 seconds by putting in some hacks. I'm not suggesting you apply these hacks, but just wanted to demonstrate that it should be possible in principle to get fast startup.
@@ -1307,6 +1307,8 @@ nvm() {
PROVIDED_VERSION="$NVM_RC_VERSION"
VERSION="$(nvm_version "$PROVIDED_VERSION")"
fi
+ elif [ "$2" == default ]; then # performance
+ VERSION="$(< ~/.nvm/alias/default)"
else
local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)" There is a @@ -1347,7 +1349,6 @@ nvm() {
return 8
fi
- nvm_ensure_version_installed "$PROVIDED_VERSION"
EXIT_CODE=$?
if [ "$EXIT_CODE" != "0" ]; then
return $EXIT_CODE And finally checking for the presence of a @@ -1718,7 +1719,7 @@ if nvm_supports_source_options && [ "_$1" = "_--install" ]; then
elif nvm_rc_version >/dev/null 2>&1; then
nvm install >/dev/null
fi
-elif nvm ls default >/dev/null; then
+elif [ -f ~/.nvm/alias/default ]; then
nvm use default >/dev/null
elif nvm_rc_version >/dev/null 2>&1; then
nvm use >/dev/null |
Thanks for researching this! Of these three optimizations: I'm not opposed to the first "else" check, but the The second can't happen - that's inside As for the third one - I'd be fine switching that line to In summary, I definitely want performance to improve! However, |
Yes, it does - perfect.
Yes, it does. (Nitpick: I think it needs to be
Right. Maybe there's some way to have a separate (faster) code path for initial sourcing, but I understand that you want things to stay maintainable. :) |
Awesome! Would you like to prepare a PR for those 2 changes? If not, I'll take care of it, but I don't want to steal your thunder. |
Sure: #705 |
Awesome! This speed boost makes a huge difference. |
Improve startup performance. Closes #703
Still takes almost a second for me to startup. If I remove the |
There's still work to be done here, clearly. The odd thing is that it's lightning fast on my Mac(s), but enough people have had this issue that it's probably something in my environment allowing it to be fast, not something in yours making it slow. |
My problem is also that I had to add that both to my .zshrc and .zprofile for nvm to work on my terminal and for sublime plugins to be able to use node. this makes the startup time twice the normal it has to be. .zprofile: http://puu.sh/ibneI/065bcb95e0.png |
Those are the same link. But also, presumably there's a better way to set up the profile files so that's not necessary? ie, a file that |
Yeah my bad, I fixed the second link. Not sure how I can make it so that zsh sources once in all cases though. |
i was able to set a custom path for node on my sublime plugin. Now I am only running the shell script once on shell startup. This still has a ~.5 second startup time though. |
Anecdotally: I'm seeing a consistent 0.93 - 1.5 second slowdown on every launch. nvm 0.28.0 |
@dylanpyle Are you using |
@ljharb not using
Yep, looks like it! Seems like I can just stick something like:
in my zshrc, and an |
Certainly you can hardcode it, but it shouldn't be necessary :-( if you do |
Yep :(
|
@dylanpyle thanks - and to confirm as well, |
@ljharb aha, good question.
If this is a separate issue than the parent, want me to open a new one? |
@dylanpyle please do open a new one with this timing info - I think it's the same issue but let's start with a fresh context. |
done: #860 |
People who actually read the docs should not suffer - see nvm-sh#860 and nvm-sh#703
People who actually read the docs should not suffer - see nvm-sh#860 and nvm-sh#703
~/.nvm tags/v0.33.9 ❯ zsh --version With / Without
|
I have the same issue. It is quite slow on Ubuntu 16.04 |
. ~/.nvm/nvm.sh
adds about half a second to shell startup. The main culprits seem to benvm ls default
andnvm use default
- commenting them out drops the timing reported bytime . ~/.nvm/nvm.sh
to near-zero.I wonder if we can speed those up, or replace them with a cheaper operation for shell startup?
The text was updated successfully, but these errors were encountered: