-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Shell startup can be improved by not printing npm version when sourcing nvm.sh #781
Comments
Also some data points that I'm quite pleased with: Before
After
|
I am removing nvm from my shell for the time being, since it is currently adding too much lag when spawning a new shell. |
@jottr do you use I'll be merging #780 soon which should help a lot (thanks @alanmquach for that) |
@ljharb yes, I am using |
@jottr trusty ol' @ljharb FWIW, I'm using |
@alanmquach hmm, what OS are you using? |
@ljharb OSX Yosemite on a MacBook Pro 2.9Ghz i5 |
@alanmquach Can you gist me your profile files? I have a similar setup and have never run into trouble. |
Adding --silent option for nvm use, and using it to disable processing certain output to speed up shell startup Relates to #781.
@alanmquach in bash, if you comment out those shopt lines, does Because |
@ljharb I commented out everything in my Times are a bit faster on my Ubuntu box (running Trusty), although I did notice there was a clear regression between Just curious, how long does it take you to |
|
Wow! OS? Hardware? |
OS X Yosemite, rMBP 15" 2.8GHz. I do have an SSD though, so that might be part of it. |
I'm on a 2015 rMBP 13" which I think should have the new PCIe SSDs. 😕 Do you have anything special that may be speeding it up? Bash 4? |
I've got stock bash, 3.2.57. Have you tried commenting out those bash profile options, and actually opening a new shell, and then comparing the time? shopts often can't be unset after they're set. |
Yep. I actually commented out everything. Restarted Terminal (just in case) and confirmed that those options were not set. This is quite puzzling. What is your nvm configuration? Do you have a system The only other thing I can think of is for me to really dig into where time is being spent on my system and micro benchmark the low level operations shell operations between our systems... |
Oh, also I assume you have an i7 with 2 more cores. I can try to grab some people on Monday with an i5 and an i7 for a few more data points. See if that's what it is. |
i7, yes. No system node, altho my previous machine did and I never ran into trouble either. |
FYI
The --silent switch speeds things up considerably:
I'm on a MacBook Pro:
|
Performance isn't so hot for me either. My machine characteristics are similar to @moander's, but with less RAM. Here's the outcome of sourcing nvm.sh on my (vanilla) bash shell.
Here's a gist with the output of zprof when sourcing
https://gist.github.com/totallymike/856c80bca85087df55af For reference, here's what the docs say about zprof output
|
Here is a dirty workaround to the terminal startup annoyance. .bash_profile:
Replace v5.4.0 to with your preferred default node version :) |
It's very unwise to bake a hardcoded path into your profile file. In addition, that will mean nvm bash completion will be unavailable until you've invoked |
It depends on individual usage patterns. I'm opening new terminals all the time.. Say 200 times a day in average. That adds up to one full hour of waiting time each month.. So I can not support your claim that it is unwise to instead having to type nvm for it to fully enable bash completion for the rest of terminal lifetime. It's simple math. If you open a terminal more often than you need nvm bash completion you are better off with lazy loading. (my opinion) :) |
@moander I completely agree with you. I was wondering why my terminal was starting up so slowly, even with an SSD. It would take around ~800ms to load, which is a buzzkill. Now I can just invoke |
I think the culprit is the npm config get prefix call, as noted in #966 . Which is a huge bummer because now every new terminal is running a node process that interprets and executes
|
That check is critical, but I'm always open to PRs to speed it up. Sadly the logic npm uses to get that config item is very complex. |
I had actually taken a look at it (the code within Would it be possible to fix #606 differently? Like actually adding support to |
It's more that the concept of an npm prefix is tightly coupled to the concept of their being one version of npm - it just doesn't make any sense to use it. What might make sense is storing global modules elsewhere - but that's a lot of complexity just for nvm to have to manage a different directory. |
Is there any update on this ? I'm running into slow startup times especially when I start tmux. I usually spawn like 30 different shells in tmux, and everytime I start a new tmux session, I hit this issue. It has actually been worse on my Linux box than Mac. |
@alanmquach if you want to check out the latest version of nvm, and rerun your profiling, I'd love to hear your results. The |
@ljharb here are my current timings on
Might also be worth noting that while the hardware profile is similar to my last system, current one feels more sluggish than the last. |
Glad I am not the only one having this issue. I've noticed that on slower machines (specifically my Raspberry Pi), it takes up to 8 extra seconds for my shell to start up. |
Someone wrote a blog post about a workaround for this: |
Based on the link posted by @eladnava and the reddit link in that page (which was buggy BTW), I made a few changes and this seems to work:
|
@Tuxdude that will grab all node globals, including ones that are only available in a node version that isn't the default one - is that the intent? |
@ljharb - Yes I realized the script pulls globally installed binaries from all versions of node (same as what was posted on that reddit page's comments). If there is a way to determine which version of node to use (or the default node version), we can use just that path in the find command. |
Sadly, I suspect that the slow part is indeed determining that. |
nvm takes on average half of a second to load, which is more than whole prezto takes to load. This can be noticed when you open a new shell. To avoid this, we are creating placeholder function for nvm, node, and all the node packages previously installed in the system to only load nvm when it is needed. This code is based on the scripts: * https://www.reddit.com/r/node/comments/4tg5jg/lazy_load_nvm_for_faster_shell_start/d5ib9fs * http://broken-by.me/lazy-load-nvm/ * nvm-sh/nvm#781 (comment)
nvm takes on average half of a second to load, which is more than whole prezto takes to load. This can be noticed when you open a new shell. To avoid this, we are creating placeholder function for nvm, node, and all the node packages previously installed in the system to only load nvm when it is needed. This code is based on the scripts: * https://www.reddit.com/r/node/comments/4tg5jg/lazy_load_nvm_for_faster_shell_start/d5ib9fs * http://broken-by.me/lazy-load-nvm/ * nvm-sh/nvm#781 (comment)
nvm takes on average half of a second to load, which is more than whole prezto takes to load. This can be noticed when you open a new shell. To avoid this, we are creating placeholder function for nvm, node, and all the node packages previously installed in the system to only load nvm when it is needed. This code is based on the scripts: * https://www.reddit.com/r/node/comments/4tg5jg/lazy_load_nvm_for_faster_shell_start/d5ib9fs * http://broken-by.me/lazy-load-nvm/ * nvm-sh/nvm#781 (comment)
I found that the slowest part (0.5s, so not horrible) of my shell startup was sourcing nvm.sh so out of curiosity, I dove in to see what it was spending all it's time doing.
While considerable time is spent in:
nvm_version
nvm_ensure_version_installed
They're at least doing useful work. Also
nvm_ensure_version_installed
has already been flagged as a possible optimization.I almost overlooked the
echo
statements at the end but found thatnvm_print_npm_version
takes just as much time as the heavy hitters above, all just to print the npm version (presumably because it calls out tonpm --version
). Moreover, while this might be useful info, it certainly isn't when it gets>/dev/null
ed as it does in the shell startup case.Opened #780 for this. Not sure if it's the cleanest but that's the idea. I'd be happy to implement it in a cleaner way needed.
The text was updated successfully, but these errors were encountered: