-
-
Notifications
You must be signed in to change notification settings - Fork 753
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
Copying node is slow #831
Comments
Also, hard links do not work across partitions, and the cache destination and install destination may be on different partitions.
I appreciate that you recognise switching to symlinks would be major and unlikely, but adding a partial feature to make it possible to opt-in is... a bit weird and overly specific. 😆 For interest, my recollection is this is similar to how |
The two supported ways of avoiding or lowering the copy cost are:
|
For my own interest I did a quick check, and % time n 22.13.1
copying : node/22.13.1
installed : v22.13.1 (with npm 10.9.2)
n 22.13.1 0.18s user 1.09s system 45% cpu 2.797 total
% time n 22.13.1
copying : node/22.13.1
installed : v22.13.1 (with npm 10.9.2)
n 22.13.1 0.18s user 1.07s system 46% cpu 2.676 total
% time n --preserve 22.13.1
copying : node/22.13.1
installed : v22.13.1
n --preserve 22.13.1 0.09s user 0.44s system 29% cpu 1.815 total
% time n --preserve 22.13.1
copying : node/22.13.1
installed : v22.13.1
n --preserve 22.13.1 0.09s user 0.44s system 28% cpu 1.853 total |
Yeah, that's a good point. Personally, I would still use it (I'd test one But that's up to you :) Side note (related to the below): I think that Finally, I'm actually interested in the symlink thing not only because of the performance issue, but also because I very much prefer that approach, since it keeps things very tidy. (I never have issues with preserving I realize that using I also considered some wrapper script (eg, some ...BUT..., looking at the new I actually thought for a while that the only way out would be a fork, but then I realized that there's a nice way to do this which requires a VERY small change that I will do in a followup PR. |
The big functional difference with running versions of node from separate folders, whether using symlinks or jumpers, is the impact on global packages. I have had one try at a lightweight way of using symlinks but I abandoned it because it wouldn't be just an under-the-hood change. I see other managers have commands and behaviour related to managing global packages like nvs migrate.
I will be interested to see, but not optimistic it will be accepted. 😄 |
The first usage of The documented usage is to enable downloading, as you expected. |
My musing from thinking about links during a walk is |
This is the tiny change that I talked about in tj#831. The actual change is both the extra line, plus a vague highlevel decision to keep this output intact in face of future change. Looks like a very small change (which I promised :) and also likely to be accepted since it's a harmless one line of output --- BUT --- with this, I can use `n` to manage the downloading + caching of various versions, but use my own system for actually "activating" it. In my use case, I'd write a small script that uses `n <ver> --quiet --download` to just have some version available. With this PR in place, I can parse the output and look for `^ *(mk)?dir : `. That gives me the directory which I will then use as a `/usr/local/node` symlink (with `/usr/local/bin/*` symlinks into that main `node` symlink). AAt a higher level, this makes it possible to use the download-and-cache functionality of `n` with any way of using the results. This could open up more uses in the future to have more alternative activations. I specifically think now that some disconnected `n link <ver>` would be an awkward addition, since it would look like a side-think that is bolted on, since it would be disconnected from the main way of activating a version. That's why I originally thought about something along the lines of adding a "mode" thing, but as I said in that thread, that would be a major change. Especially with things like `--cleanup` that won't fit with it. At a minimum, it would make it easy to play with alterrnative activations before adding it to the main code.
Well, originally, I wanted to hook into "the currently activated version", so (Re |
Copying a big directory is slow.
Using symlinks is much lighter, but obviously there's too many issues.
I have two suggestions:
First,
cp -l
creates a hard link, which is of course much faster, and the result is very close to a plaincp
so there shouldn't be any issues. For example, a very lightweight change would be to setCP="cp -l"
and use that instead of allcp
s. (CP_OPTIONS
is better, but maybe that's too big of a change.)Second, having a symlink based thing is nice not only in being fast, but also in keeping things more organized, since the downloaded stuff is kept in a single place. But of course adding that properly is expensive + risky so unlikely to be desirable.
A possible way to get that with minimal changes could be:
/usr/local/n/versions/node/current -> 22.13.1
. That should be just a one-line thing to create/set it before copying. This effectively adds a proper place that remembers the current version directly rather thannode --version
.--no-copy
flag (better: envvar (better: both)) to completely skip copying (so just the above symlink is changed). This is probably also a very small change.This means that I can maintain my own
bin/*
symlinks tocurrent/bin/*
, and others if I want to.Now, this looks like a weird and overly specific feature, but a good way to think about it is that
n
has functionality to (A) get some node version, and more functionality to (B) install it. This suggestion makes it possible to use (A) without (B). (IOW: useinstalll()
withoutactivate()
.)This is very close to using
--download
, the only difference is that it's still doing the symlink change. A tiny change would be to rename$DOWNLOAD
to a$MODE
internally, so it can have three values for downloading only, or also doing the symlink, or also doing the whole thing.Again, I can do PRs for both of these if it sounds reasonable. I'm guessing that they will be very small overall.
The text was updated successfully, but these errors were encountered: