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): Optimize FFI Rust side type checks #14923

Merged
merged 3 commits into from Jun 21, 2022

Conversation

aapoalas
Copy link
Collaborator

Minor optimisation to FFI parameters' Rust side type checking / extraction.

Main change is avoiding ZeroCopyBuf in pointer extraction, as ZeroCopyBuf extracts and carries unnecessary information like the length of the buffer being pointed to. For FFI pointers, we are only interested in the actual pointer and not at all in the length of the buffer.

Additionally, double type checks are avoided by liberal application of if let Ok(value) = v8::Local::<v8::SomeType>::try_from(value). This doesn't show particularly high impact but maybe there's still something.

Relevant comparisons:

Bench Pre-change (current main) Post-change (this PR)
nop_u64() 447.64 ns/iter 450.94 ns/iter
nop_i64() 454.48 ns/iter 443.68 ns/iter
nop_usize() 448.33 ns/iter 449.93 ns/iter
nop_isize() 450.39 ns/iter 446.78 ns/iter
nop_buffer() 576.09 ns/iter 516.99 ns/iter
return_u64() 329.06 ns/iter 322.48 ns/iter
return_i64() 329.76 ns/iter 321.93 ns/iter
return_usize() 332.15 ns/iter 326.04 ns/iter
return_isize() 332.56 ns/iter 317.97 ns/iter
return_buffer() 331.82 ns/iter 320.1 ns/iter
nop_u64_nonblocking() 726.02 ns/iter 707.74 ns/iter
nop_i64_nonblocking() 713.36 ns/iter 712.2 ns/iter
nop_usize_nonblocking() 719.49 ns/iter 698.76 ns/iter
nop_isize_nonblocking() 709.2 ns/iter 707.5 ns/iter
nop_buffer_nonblocking() 851.82 ns/iter 773.95 ns/iter
return_u64_nonblocking() 532.23 ns/iter 545.31 ns/iter
return_i64_nonblocking() 534.77 ns/iter 528.94 ns/iter
return_usize_nonblocking() 539.35 ns/iter 541.26 ns/iter
return_isize_nonblocking() 517.91 ns/iter 530.17 ns/iter
return_buffer_nonblocking() 522.23 ns/iter 522.57 ns/iter
nop_many_parameters() 2.85 µs/iter 2.63 µs/iter
nop_many_parameters_nonblocking() 5.68 µs/iter 5.45 µs/iter

As can be seen, the BigInt types don't really change in a way that can be said to definitely have an effect. However, buffers are now measurably more performant.

@aapoalas aapoalas changed the title Optimize FFI Rust side type checks feat(ext/ffi): Optimize FFI Rust side type checks Jun 20, 2022
@aapoalas aapoalas changed the title feat(ext/ffi): Optimize FFI Rust side type checks perf(ext/ffi): BREAKING: Optimize FFI Rust side type checks Jun 20, 2022
@aapoalas aapoalas changed the title perf(ext/ffi): BREAKING: Optimize FFI Rust side type checks perf(ext/ffi): Optimize FFI Rust side type checks Jun 20, 2022
Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@littledivy littledivy merged commit 82655b9 into denoland:main Jun 21, 2022
@aapoalas aapoalas deleted the feat/optimize-ffi-rust-checks branch July 10, 2022 08:56
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