-
-
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
Optimize shell startup with lazy loading? #730
Comments
This is related to/a duplicate of #709. Can you elaborate on option 1? I'm not sure what benefit this would offer, as the As for option 2, while you certainly could do something like this: nvm() {
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
nvm $@
} … the complexity of adding that to the install script, which already has issues even adding the single "source" line (see https://github.com/creationix/nvm/labels/installing%3A%20profile%20detection), worries me a lot. |
Why would the PATH be different each time you load a shell? After each call to
|
I have multiple shells open at once, and I could easily change the |
That's a good caveat to this design. |
I'll leave this open as a "lazy load" feature request, for sure. |
Hey, lazy loading nvm in this way drops startup for new shells from a second to half a second, which is great! But Suggestions on how to source |
I added this function, which seems to work well enough 😄 Suggestions appreciated! |
That approach will still only work for whichever things you hardcode - |
And as it halves the time it takes to open a new shell, I think it's worth it. Duplicating that sort of function isn't much work if I need to either. |
Officially the suggestion is to not load nvm lazily, and to either tolerate the time it takes to load, or write me a PR to make it faster ;-) However, the approach in your example is fine if you are aware of the caveats, and if you'll remember that you've done that when debugging any issues that pop up in the future. |
SimenB my load_nvm function is pretty fragile but it basically does what you're looking for, it caches the paths to the loaded npm and node binaries by writing them to a file, and then I have that file sourced in my zshrc, so then future shells get npm and node added to the PATH without loading nvm. It's really broken because, like you, I don't know bash.. I just hacked together some snippits from SO.. But it works and can be improved by learning a wee bit of bash.. |
is there any final solution? |
For anyone here using zsh interested in lazy loading I've just added support for lazy loading in I'm getting about 70x faster startup times (874ms down to 12ms) |
lukechilds' plugin is cool. |
While playing around with zsh frameworks (I ended up using zgen) I discovered that nvm is the slowest part of my shell startup. I don't actually know bash but somehow made this hack to speed it up, which helped me think of a better mechanism for lazy loading nvm:
$PATH
Every time nvm is run, it should re-cache the
$PATH
segment before exiting. I cached the$PATH
segment into a self-contained shell script, nameduse_cached_nvm_bins.sh
, but maybe symlinks could be used instead of caching to a file.nvm
nvm.sh would be reduced to a very small file that prepends the cached node binary path to your
$PATH
and only loads the bulk of the code when nvm is invoked. In my hack I was so lazy I didn't even load nvm, and wrote aload_nvm
function instead.The text was updated successfully, but these errors were encountered: