forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(napi): optimize primitive napi functions (denoland#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 ```
- Loading branch information
1 parent
be80c57
commit e136bd8
Showing
7 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use napi_sys::*; | ||
use std::ptr; | ||
|
||
extern "C" fn test_get_undefined( | ||
env: napi_env, | ||
_: napi_callback_info, | ||
) -> napi_value { | ||
let mut result = ptr::null_mut(); | ||
unsafe { napi_get_undefined(env, &mut result) }; | ||
result | ||
} | ||
|
||
pub fn init(env: napi_env, exports: napi_value) { | ||
let properties = &[crate::new_property!( | ||
env, | ||
"test_get_undefined\0", | ||
test_get_undefined | ||
)]; | ||
|
||
unsafe { | ||
napi_define_properties(env, exports, properties.len(), properties.as_ptr()) | ||
}; | ||
} |