summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-10-07 03:54:01 -0700
committerGitHub <noreply@github.com>2022-10-07 16:24:01 +0530
commite136bd86b3bf0a14d3379b389a44547d332b9ca5 (patch)
treefc13ec6bb7a5a9b2ddd051789e482f4bd8e0dcb5 /cli
parentbe80c57b3c65ab8dd074e8a1487b8830843a7ac9 (diff)
perf(napi): optimize primitive napi functions (#16163)
This optimization applies on `napi_get_undefined`, `napi_get_null` & `napi_get_boolean`. ``` # main benchmark time (avg) (min … max) p75 p99 p995 ---------------------------------------------------------- ----------------------------- warmup 482.55 ps/iter (462.5 ps … 15.67 ns) 475 ps 525 ps 829.1 ps napi_get_undefined 25.07 ns/iter (24.03 ns … 36.87 ns) 25.37 ns 27.09 ns 34.85 ns ``` ``` # This patch benchmark time (avg) (min … max) p75 p99 p995 ---------------------------------------------------------- ----------------------------- warmup 484.78 ps/iter (462.5 ps … 14.4 ns) 475 ps 554.1 ps 583.3 ps napi_get_undefined 15.52 ns/iter (15.35 ns … 22.14 ns) 15.41 ns 17.18 ns 20.02 ns ```
Diffstat (limited to 'cli')
-rw-r--r--cli/bench/napi/bench.js6
-rw-r--r--cli/bench/napi/bench_node.mjs10
-rw-r--r--cli/napi/js_native_api.rs6
3 files changed, 19 insertions, 3 deletions
diff --git a/cli/bench/napi/bench.js b/cli/bench/napi/bench.js
new file mode 100644
index 000000000..5917d3a28
--- /dev/null
+++ b/cli/bench/napi/bench.js
@@ -0,0 +1,6 @@
+import { loadTestLibrary } from "../../../test_napi/common.js";
+
+const lib = loadTestLibrary();
+
+Deno.bench("warmup", () => {});
+Deno.bench("napi_get_undefined", () => lib.test_get_undefined(0));
diff --git a/cli/bench/napi/bench_node.mjs b/cli/bench/napi/bench_node.mjs
new file mode 100644
index 000000000..7bfb63814
--- /dev/null
+++ b/cli/bench/napi/bench_node.mjs
@@ -0,0 +1,10 @@
+import { run, bench } from "mitata";
+import { createRequire } from "module";
+
+const require = createRequire(import.meta.url);
+const lib = require("../../../test_napi.node");
+
+bench("warmup", () => {});
+bench("napi_get_undefined", () => lib.test_get_undefined(0));
+
+run(); \ No newline at end of file
diff --git a/cli/napi/js_native_api.rs b/cli/napi/js_native_api.rs
index 31e021f70..32f4b787e 100644
--- a/cli/napi/js_native_api.rs
+++ b/cli/napi/js_native_api.rs
@@ -1333,7 +1333,7 @@ fn napi_get_boolean(
) -> Result {
let env: &mut Env = env.as_mut().ok_or(Error::InvalidArg)?;
let value: v8::Local<v8::Value> =
- v8::Boolean::new(&mut env.scope(), value).into();
+ v8::Boolean::new(env.isolate(), value).into();
*result = value.into();
Ok(())
}
@@ -1520,7 +1520,7 @@ fn napi_get_new_target(
fn napi_get_null(env: *mut Env, result: *mut napi_value) -> Result {
let env: &mut Env = env.as_mut().ok_or(Error::InvalidArg)?;
- let value: v8::Local<v8::Value> = v8::null(&mut env.scope()).into();
+ let value: v8::Local<v8::Value> = v8::null(env.isolate()).into();
*result = value.into();
Ok(())
}
@@ -1611,7 +1611,7 @@ fn napi_get_typedarray_info(
#[napi_sym::napi_sym]
fn napi_get_undefined(env: *mut Env, result: *mut napi_value) -> Result {
let env: &mut Env = env.as_mut().ok_or(Error::InvalidArg)?;
- let value: v8::Local<v8::Value> = v8::undefined(&mut env.scope()).into();
+ let value: v8::Local<v8::Value> = v8::undefined(env.isolate()).into();
*result = value.into();
Ok(())
}