From a250b00c5fc1ff3177cca5d779f62617accbdfe1 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Wed, 27 Dec 2023 17:37:06 +0100 Subject: [PATCH] Improved `RowToJS` performance by removing unnecessary `Napi::String::New` instantiation 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 --- src/statement.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/statement.cc b/src/statement.cc index b39f0c83..58673250 100644 --- a/src/statement.cc +++ b/src/statement.cc @@ -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);