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

perf(cli): Optimize setting up node_modules on macOS #23980

Merged
merged 9 commits into from
May 28, 2024

Conversation

nathanwhit
Copy link
Member

@nathanwhit nathanwhit commented May 25, 2024

Hard linking (linkat) is ridiculously slow on mac. copyfile is better, but what's even faster is clonefile. It doesn't have the space savings that comes with hardlinking, but the performance difference is worth it imo.

❯ hyperfine -i -p 'rm -rf node_modules/' '../../d7/target/release/deno cache npm:@11ty/eleventy' 'deno cache npm:@11ty/eleventy'
Benchmark 1: ../../d7/target/release/deno cache npm:@11ty/eleventy
  Time (mean ± σ):     115.4 ms ±   1.2 ms    [User: 27.2 ms, System: 87.3 ms]
  Range (min … max):   113.7 ms … 117.5 ms    10 runs

Benchmark 2: deno cache npm:@11ty/eleventy
  Time (mean ± σ):     619.3 ms ±   6.4 ms    [User: 34.3 ms, System: 575.6 ms]
  Range (min … max):   612.2 ms … 633.3 ms    10 runs

Summary
  ../../d7/target/release/deno cache npm:@11ty/eleventy ran
    5.37 ± 0.08 times faster than deno cache npm:@11ty/eleventy

@@ -492,6 +492,68 @@ pub async fn remove_dir_all_if_exists(path: &Path) -> std::io::Result<()> {
}
}

mod clone_dir_imp {
Copy link
Member

Choose a reason for hiding this comment

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

There is a similar optimization for cp and copyFile APIs. It uses rayon for recursive clonefile and has some other optimizations for small files and fallbacks:

fn cp(from: &Path, to: &Path) -> FsResult<()> {

Maybe could be reused?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure we should use rayon in non-js sync specific scenarios. I feel like that might make stuff slower by using another thread pool.

Copy link
Member Author

Choose a reason for hiding this comment

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

Gave it a shot anyway, no performance difference but I found it caused a failure when the destination is a directory that already exists - didn't dig into it but seems like something wasn't getting copied over properly (the panic is from setting up the bin entries – the origin file we're trying to symlink doesn't exist)

thread 'main' panicked at cli/npm/managed/resolvers/local/bin_entries.rs:89:48:
called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }

cli/util/fs.rs Outdated Show resolved Hide resolved
Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

LGTM, just two comments

@lucacasonato
Copy link
Member

@dsherret ptal if this looks good to you

@marvinhagemeister
Copy link
Contributor

Looking forward to this as a mac user 🚀

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

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

Nice!

It doesn't have the space savings that comes with hardlinking, but the performance difference is worth it imo.

Agree. Storage is cheap.

@nathanwhit nathanwhit merged commit 3e8f29a into denoland:main May 28, 2024
17 checks passed
@nathanwhit nathanwhit deleted the set-up-dirs-opt-mac branch May 28, 2024 18:59
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.

None yet

5 participants