Skip to content
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

No more symlinks on Windows #1552

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

rcsilva83
Copy link

Replace file symlink by shims and dir symlinks on Windows by junctions

closes #1397

@rcsilva83
Copy link
Author

Hi,

I'm trying to fix the tests but I couldn't make them load on VS Code's Testing panel. I'm not a Rust developer but I'm searching on the Internet and installed all VS Code's extensions for Rust testing and I couldn't make it work. Can someone help me?

Copy link
Contributor

@charlespierce charlespierce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this and many apologies on the delayed response! Left some comments / suggestions on the implementation. At a higher level, I'm a little wary of the overhead from this approach in general - it's an extra indirection of calling a child command which isn't free. This is the hottest path for Volta and one of the design goals of the project is to have as low startup as possible, so that users ideally can't tell that Volta is intercepting & redirecting their commands.

For Unix especially, we should likely continue to take advantage of symlinks, as there aren't the same set of security / usability concerns on those platforms.

Finally, for the failing tests, it appears that there are a couple of files in the tests directory that import the symlink_file method, which no longer exists. This is causing a compile failure when trying to compile the tests.

crates/volta-core/Cargo.toml Outdated Show resolved Hide resolved
crates/volta-core/src/fs.rs Outdated Show resolved Hide resolved
crates/volta-core/src/shim.rs Outdated Show resolved Hide resolved
crates/volta-layout/Cargo.toml Outdated Show resolved Hide resolved
crates/volta-layout/src/v4.rs Outdated Show resolved Hide resolved
crates/volta-migrate/src/v4.rs Outdated Show resolved Hide resolved
crates/volta-migrate/src/v4.rs Outdated Show resolved Hide resolved
src/volta-shim.rs Outdated Show resolved Hide resolved
@rcsilva83
Copy link
Author

@charlespierce is there anything else I need to do?

@Xstoudi
Copy link

Xstoudi commented Mar 14, 2024

Any update? Could be awesome to merge it is ready to allow company-constrained environment to run Volta.

Copy link
Contributor

@charlespierce charlespierce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a high-level, do you have any details about the runtime cost of this on Windows? Adding an extra indirection should be relatively quick, but it might not be negligible. What I've done in the past to test this is to use a tool like hyperfine to do a bunch of runs calling node -v (which necessarily goes through the shim) to get a sense for the overhead that Volta imposes. We don't need super significant results, just a sense of how the startup time is impacted.

crates/volta-core/src/fs.rs Outdated Show resolved Hide resolved
crates/volta-migrate/src/v4.rs Outdated Show resolved Hide resolved
src/volta-shim.rs Outdated Show resolved Hide resolved
src/volta-shim.rs Show resolved Hide resolved
@Xstoudi
Copy link

Xstoudi commented Mar 22, 2024

Running hyperfine, this is the result on the current Volta official release on my Windows 10 virtual machine:

Benchmark 1: node -v
  Time (mean ± σ):      47.7 ms ±  10.7 ms    [User: 13.1 ms, System: 25.8 ms]
  Range (min … max):    40.0 ms …  93.9 ms    57 runs

And this is the result on the release exec compiled from this pull request, again on my Windows 10 virtual machine:

Benchmark 1: node -v
  Time (mean ± σ):      46.7 ms ±   3.6 ms    [User: 12.8 ms, System: 29.7 ms]
  Range (min … max):    42.8 ms …  65.0 ms    55 runs

I'm not really sure how to interpret this and it's the first time I ever use hyperfine.

Copy link
Contributor

@charlespierce charlespierce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One remaining issue with unilaterally changing the behavior for all platforms when the change is intended to impact Windows.

Separately, reviewing this and continuing to think things through, I wonder if we could leverage volta run for all of the Windows use-cases? It is already set up to work similarly to what we're building in this change: Reading the command from the later arguments rather than the name of the executable. We're also already building a helper script as part of setting up Windows shims. I suspect we could make the "shims" for Windows be .cmd files with a short script that calls volta run {arguments} directly, which would then have the same effect as this change while requiring less overall churn.

I'm going to rough up that approach, which combined with the change here to use junctions rather than directory symlinks may achieve the same goals.


let result = ensure_layout().and_then(|()| execute_shim(&mut session).into_result());
pub fn main() -> ExitCode {
let result = Command::new("volta-runner").args(std::env::args()).status();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still a little unsure about making this the behavior for all platforms. It's relatively minor, but it is another indirection and since Rust std::process::Command doesn't use exec, it may cause unexpected issues on top of any small performance hit.

One that comes to mind is signals (e.g. pressing Ctrl-C in the terminal while a process is running). We don't handle them perfectly right now, but I know a lot of work went into making sure that Ctrl-C would cancel the underlying Node process (as a user would expect), not only the wrapper process.

Copy link
Author

@rcsilva83 rcsilva83 May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Charles!

Thank you for the feedback.

So you prefer this change is changed only for Windows, right? We can make this condition, no problem.

About the volta run and .cmd idea, let me know if you prefer that approach and I'll try to implement it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if we move forward here, we should limit the scope to only for Windows, so that we have the smallest possible blast radius.

For the volta run idea, I want to do a quick prototype to see if it's feasible, then we can look at which approach makes the most sense.

And thank you again for persisting with this change, despite our busy schedules making the lead times really long! It will be a big improvement in Windows behavior when we don't need the "Developer Mode" warning 💥

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! So I'll wait for you before making both changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dismiss the use of symlinks on Windows
3 participants