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(node/fs/copy): reduce metadata lookups copying directory #27495

Merged

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Dec 29, 2024

> cat main.mjs
import { cpSync, rmdirSync } from "node:fs";

for (let i = 0; i < 100_000; i++) {
  cpSync("folder", "other", {
    force: true,
    recursive: true
  });
  rmdirSync("other");
}
> Measure-Command { node main.mjs }
32313.49
> Measure-Command { deno run -A main.mjs }
27379.9646
> Measure-Command { ../deno/target/debug/deno run -A main.mjs } # notice this is debug--i'm too lazy to check release
11628.361

@dsherret dsherret changed the title perf(node/fs/copy): reduce metadata lookups perf(node/fs/copy): reduce metadata lookups copying directory Dec 29, 2024
@@ -723,30 +723,34 @@ fn cp(from: &Path, to: &Path) -> FsResult<()> {
}
}

match (fs::metadata(to), fs::symlink_metadata(to)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

It's faster because we avoid the second symlink_metadata lookup when the first metadata call is a directory.

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.

Noice

@dsherret dsherret merged commit fd8400e into denoland:main Dec 30, 2024
17 checks passed
@dsherret dsherret deleted the perf_reduce_metadata_lookups_fs_copy branch December 30, 2024 05:36
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.

2 participants