-
-
Notifications
You must be signed in to change notification settings - Fork 8k
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
NVM is slow (> 650ms) #1242
Comments
You can avoid the need to unalias by adding There's two main things that make it slow right now - one is the I'd start by comparing the code paths with and without |
Aha! I'll take a look and report back 👍 |
Hey guys! I wrote a simple app (kinda) called znvm that combines a bunch of solutions given over here for zsh users.
check it out: https://github.com/Kasahs/.znvm |
This 600ms or so delay on EVERY shell start was driving me mad too. 'node' and 'npm' themselves seem to work just fine with the nvm setup only in ~/.profile. So if you're happy to stick with the defaults, all is well. But then I found "nvm" wouldn't work in shells started from the GUI desktop, because 'nvm' itself is a shell function and hence not exported through sub-shells. So I came up with this dirty hack:
And then in ~/.bashrc:
Maybe it's not quite so 'dirty'... Seems to work like a charm... |
@peternann the major downside there is that |
@ljharb - As I mentioned in the post, that's not what I am observing - node, npm, etc work just fine, even before my nvm trigger function is ever run. I've updated the message above to include the 2-parts of the approach, for abundant clarity. I'm not 100% sure how nvm works, but I think running the setup once, in .profile/.bash_profile puts enough in place (in exported environment) for node/npm to run. Only 'nvm' itself has trouble (being a shell function and not usually exportable), thus the JIT code above. |
@peternann ah, interesting - you're saying that the PATH gets inherited from That seems like it might be an interesting solution, if it works across platforms. |
@ljharb Well, yes, PATH is definitely inherited safely by all sub-shells. The Unix world would fall into a heap if not... And yes, it's just functions (like nvm here) that are not reliably inherited. Like I said - The setup above is working like a charm for me. |
I wrapped the startup code inside a function like @peternann did, It's much better to get a ~600ms delay when you will actually use |
I find myself running
nvm unalias default
after everynvm install
, since it makes new shell creation so much faster. Here it is, withtime source ~/.nvm/nvm.sh
in~/.bash_profile
:After
nvm alias default node
:After
nvm unalias default
:I spend enough time away from Node (and enough time in the shell) that remembering to
nvm use
is worth the hassle.If an intrepid contributor wanted to make NVM faster, where might they start?
The text was updated successfully, but these errors were encountered: