Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(ext/ffi): Optimise common pointer related APIs #15144

Merged
merged 16 commits into from
Jul 22, 2022

Conversation

aapoalas
Copy link
Collaborator

@aapoalas aapoalas commented Jul 10, 2022

Optimises a few of the more common pointer related APIs:

  1. Deno.UnsafePointer.of
  2. Deno.UnsafePointerView#getCString

Both optimisations are just by-now standard op(v8) usages.

Deno.UnsafePointer.of

Before:

benchmark                  time (avg)             (min … max)       p75       p99      p995
------------------------------------------------------------- -----------------------------
Deno.UnsafePointer.of  253.92 ns/iter (219.88 ns … 351.89 ns) 260.71 ns 343.19 ns 351.32 ns
Mesmeria% ./target/release/deno bench --unstable -A ./test_ffi/tests/bench.js --filter UnsafePointer
cpu: AMD Ryzen 5 3600 6-Core Processor
runtime: deno 1.23.3 (x86_64-unknown-linux-gnu)

After:

benchmark                  time (avg)             (min … max)       p75       p99      p995
------------------------------------------------------------- -----------------------------
Deno.UnsafePointer.of     205 ns/iter (185.63 ns … 255.27 ns) 210.14 ns  240.7 ns 246.87 ns
Mesmeria% ./target/release/deno bench --unstable -A ./test_ffi/tests/bench.js --filter UnsafePointer
cpu: AMD Ryzen 5 3600 6-Core Processor
runtime: deno 1.23.3 (x86_64-unknown-linux-gnu)

Around 20% performance improvement, from ~250ns to ~200ns.

Deno.UnsafePointerView#getCString

Before:

benchmark                              time (avg)             (min … max)       p75       p99      p995
------------------------------------------------------------------------- -----------------------------
Deno.UnsafePointerView#getCString   264.1 ns/iter (229.11 ns … 350.57 ns) 269.65 ns 347.72 ns 350.26 ns
Mesmeria% ./target/release/deno bench --unstable -A ./test_ffi/tests/bench.js --filter getCString
cpu: AMD Ryzen 5 3600 6-Core Processor
runtime: deno 1.23.3 (x86_64-unknown-linux-gnu)

After:

benchmark                              time (avg)             (min … max)       p75       p99      p995
------------------------------------------------------------------------- -----------------------------
Deno.UnsafePointerView#getCString  211.06 ns/iter (173.44 ns … 306.52 ns) 211.41 ns 292.55 ns 294.84 ns
Mesmeria% ./target/release/deno bench --unstable -A ./test_ffi/tests/bench.js --filter CString
cpu: AMD Ryzen 5 3600 6-Core Processor
runtime: deno 1.23.3 (x86_64-unknown-linux-gnu)

Around 20% performance improvement, from ~265ns to around ~210ns.

@aapoalas aapoalas changed the title feat(ext/ffi): Optimise common pointer related APIs perf(ext/ffi): Optimise common pointer related APIs Jul 12, 2022
@littledivy littledivy merged commit 244c00d into denoland:main Jul 22, 2022
@aapoalas aapoalas deleted the feat-ext-ffi-optimise-common-apis branch July 23, 2022 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants