fs: improve error performance for `fsyncSync` · nodejs/node@5942edb · GitHub
Skip to content

Commit 5942edb

Browse files
Jungku Leetargos
authored andcommitted
fs: improve error performance for fsyncSync
PR-URL: #49880 Refs: nodejs/performance#106 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 6ec5aba commit 5942edb

4 files changed

Lines changed: 50 additions & 10 deletions

File tree

benchmark/fs/bench-fsyncSync.js

Lines changed: 42 additions & 0 deletions

lib/fs.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,9 +1323,7 @@ function fsync(fd, callback) {
13231323
*/
13241324
function fsyncSync(fd) {
13251325
fd = getValidatedFd(fd);
1326-
const ctx = {};
1327-
binding.fsync(fd, undefined, ctx);
1328-
handleErrorFromBinding(ctx);
1326+
return binding.fsync(fd);
13291327
}
13301328

13311329
/**

src/node_file.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,21 +1516,21 @@ static void Fsync(const FunctionCallbackInfo<Value>& args) {
15161516
Environment* env = Environment::GetCurrent(args);
15171517

15181518
const int argc = args.Length();
1519-
CHECK_GE(argc, 2);
1519+
CHECK_GE(argc, 1);
15201520

15211521
CHECK(args[0]->IsInt32());
15221522
const int fd = args[0].As<Int32>()->Value();
15231523

1524-
FSReqBase* req_wrap_async = GetReqWrap(args, 1);
1525-
if (req_wrap_async != nullptr) {
1524+
if (argc > 1) {
1525+
FSReqBase* req_wrap_async = GetReqWrap(args, 1);
1526+
CHECK_NOT_NULL(req_wrap_async);
15261527
FS_ASYNC_TRACE_BEGIN0(UV_FS_FSYNC, req_wrap_async)
15271528
AsyncCall(env, req_wrap_async, args, "fsync", UTF8, AfterNoArgs,
15281529
uv_fs_fsync, fd);
15291530
} else {
1530-
CHECK_EQ(argc, 3);
1531-
FSReqWrapSync req_wrap_sync;
1531+
FSReqWrapSync req_wrap_sync("fsync");
15321532
FS_SYNC_TRACE_BEGIN(fsync);
1533-
SyncCall(env, args[2], &req_wrap_sync, "fsync", uv_fs_fsync, fd);
1533+
SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_fsync, fd);
15341534
FS_SYNC_TRACE_END(fsync);
15351535
}
15361536
}

typings/internalBinding/fs.d.ts

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)