Skip to content

Commit

Permalink
Improved RowToJS performance by removing Napi::String::New instan…
Browse files Browse the repository at this point in the history
…tiation

refs https://github.com/nodejs/node-addon-api/blob/main/doc/object.md#set

- according to the node-addon-api docs, you can set various things as
  the key for a Napi::Object, including a std::string ref
- instantiating a `Napi::String::New` is quite heavy, especially when
  we're doing it for every row we return, so we can avoid doing that and
  speed up the function
- locally, this speeds up the benchmark by 5-15% (a lot of variance) but YMMV
  • Loading branch information
daniellockyer committed Dec 27, 2023
1 parent 77b327c commit 3372130
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/statement.cc
Expand Up @@ -814,7 +814,7 @@ Napi::Value Statement::RowToJS(Napi::Env env, Row* row) {
} break;
}

(result).Set(Napi::String::New(env, field->name.c_str()), value);
result.Set(field->name, value);
}

return scope.Escape(result);
Expand Down

0 comments on commit 3372130

Please sign in to comment.