-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
fs: improve cpSync no-filter copyDir performance #58461
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
fs: improve cpSync no-filter copyDir performance #58461
Conversation
test/parallel/test-fs-cp.mjs
Outdated
// small wait to make sure that destStat.mtime.getTime() would produce a time | ||
// different from srcStat.mtime.getTime() if preserveTimestamps wasn't set to true | ||
await setTimeout(5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change is not necessary, however without this additional wait I noticed that a non functioning preserveTimestamps
logic would not consistently make this test fail
if (!opts.filter) { | ||
// the caller didn't provide a js filter function, in this case | ||
// we can run the whole function faster in C++ | ||
// TODO(dario-piotrowicz): look into making cpSyncCopyDir also accept the potential filter function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can also look into the filter
function in this PR if preferred but I figured it could make sense to do attempt that separately
f776f77
to
54f1daf
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58461 +/- ##
==========================================
- Coverage 90.19% 90.13% -0.07%
==========================================
Files 636 636
Lines 187705 187878 +173
Branches 36852 36869 +17
==========================================
+ Hits 169306 169335 +29
- Misses 11161 11293 +132
- Partials 7238 7250 +12
🚀 New features to boost your workflow:
|
e08f0ad
to
fc55e9f
Compare
9b4154d
to
5cb540a
Compare
src/node_file.cc
Outdated
|
||
static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) { | ||
Environment* env = Environment::GetCurrent(args); | ||
Isolate* isolate = env->isolate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use args.GetIsolate() directly. No need for an environment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I am using the env
in the function below, no? 🤔
b88a8dc
to
fed9c50
Compare
src/node_file.cc
Outdated
dir_entry.path(), dest_entry_path, file_copy_opts, error); | ||
if (error) { | ||
if (error.value() == EEXIST) { | ||
THROW_ERR_FS_CP_EEXIST( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this throw... and I think that it could be nicer to just throw the EEXIST error from the C++ layer, catch it in the js layer and then throw an ERR_FS_CP_EEXIST
error from there (using the appropriate class).
I did not however go with that solution as I think that catching and re-throwing in the js layer interferes with userland debuggers that can catch those as part of options such as Pause on caught exceptions
, please let me know if you think I'm wrong and that throwing the error from the js layer could be a better choice here 🙂
34856b5
to
74ce1b2
Compare
74ce1b2
to
8e068db
Compare
8e068db
to
a3d1f74
Compare
a3d1f74
to
b71f878
Compare
ok finally it's all green! (even on windows! 😅) Sorry @anonrig the PR changed significantly after your review, could you have another look? 🙏 |
move the logic in `cpSync` that copies a directory from src to dest from JavaScript to C++ increasing its performance Note: this improvement is not applied if the filter option is provided, such optimization will be looked into separately
b71f878
to
92ed1cf
Compare
Landed in 3c351c2 |
move the logic in `cpSync` that copies a directory from src to dest from JavaScript to C++ increasing its performance Note: this improvement is not applied if the filter option is provided, such optimization will be looked into separately PR-URL: #58461 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
move the logic in `cpSync` that copies a directory from src to dest from JavaScript to C++ increasing its performance Note: this improvement is not applied if the filter option is provided, such optimization will be looked into separately PR-URL: #58461 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
move the logic in `cpSync` that copies a directory from src to dest from JavaScript to C++ increasing its performance Note: this improvement is not applied if the filter option is provided, such optimization will be looked into separately PR-URL: nodejs#58461 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
move the logic in
cpSync
that copies a directory from src to dest from JavaScript to C++ increasing its performanceNote: this improvement is not applied if the filter option is
provided, such optimization will be looked into separately
Example of perf improvement