summaryrefslogtreecommitdiff
path: root/ext/ffi/ir.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-05-27 21:01:09 -0700
committerGitHub <noreply@github.com>2024-05-28 09:31:09 +0530
commit53606de6344fca63c40fde37056910b72a3c4f8d (patch)
treec2d31a7bded8ad5402ad8582d2e4c8df1a100bda /ext/ffi/ir.rs
parentd99c6c1ea4f5711c3f48c5617d7224852fb294d2 (diff)
BREAKING(ffi/unstable): always return u64 as bigint (#23981)
The mixed `number | bigint` representation was useful optimization for pointers. Now, pointers are represented as V8 externals. As part of the FFI stabilization effort we want to make `bigint` the only representation for `u64` and `i64`. BigInt representation performance is almost on par with mixed representation with the added benefit that its less confusing and users don't need manual checks and conversions for doing operations on the value. ``` cpu: AMD Ryzen 5 7530U with Radeon Graphics runtime: deno 1.43.6+92a8d09 (x86_64-unknown-linux-gnu) file:///home/divy/gh/ffi/main.ts benchmark time (avg) iter/s (min … max) p75 p99 p995 -------------------------------------------------------------------------- ----------------------------- nop 4.01 ns/iter 249,533,690.5 (3.97 ns … 10.8 ns) 3.97 ns 4.36 ns 9.03 ns ret bigint 7.74 ns/iter 129,127,186.8 (7.72 ns … 10.46 ns) 7.72 ns 8.11 ns 8.82 ns ret i32 7.81 ns/iter 128,087,100.5 (7.77 ns … 12.72 ns) 7.78 ns 8.57 ns 9.75 ns ret bigint (add op) 15.02 ns/iter 66,588,253.2 (14.64 ns … 24.99 ns) 14.76 ns 19.13 ns 19.44 ns ret i32 (add op) 12.02 ns/iter 83,209,131.8 (11.95 ns … 18.18 ns) 11.98 ns 13.11 ns 14.5 ns ```
Diffstat (limited to 'ext/ffi/ir.rs')
-rw-r--r--ext/ffi/ir.rs43
1 files changed, 4 insertions, 39 deletions
diff --git a/ext/ffi/ir.rs b/ext/ffi/ir.rs
index 6fd1f53ea..520ead92e 100644
--- a/ext/ffi/ir.rs
+++ b/ext/ffi/ir.rs
@@ -1,8 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use crate::symbol::NativeType;
-use crate::MAX_SAFE_INTEGER;
-use crate::MIN_SAFE_INTEGER;
use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::v8;
@@ -100,46 +98,13 @@ impl NativeValue {
v8::Integer::new_from_unsigned(scope, self.u32_value).into()
}
NativeType::I32 => v8::Integer::new(scope, self.i32_value).into(),
- NativeType::U64 => {
- let value = self.u64_value;
- let local_value: v8::Local<v8::Value> =
- if value > MAX_SAFE_INTEGER as u64 {
- v8::BigInt::new_from_u64(scope, value).into()
- } else {
- v8::Number::new(scope, value as f64).into()
- };
- local_value
- }
- NativeType::I64 => {
- let value = self.i64_value;
- let local_value: v8::Local<v8::Value> =
- if value > MAX_SAFE_INTEGER as i64 || value < MIN_SAFE_INTEGER as i64
- {
- v8::BigInt::new_from_i64(scope, self.i64_value).into()
- } else {
- v8::Number::new(scope, value as f64).into()
- };
- local_value
- }
+ NativeType::U64 => v8::BigInt::new_from_u64(scope, self.u64_value).into(),
+ NativeType::I64 => v8::BigInt::new_from_i64(scope, self.i64_value).into(),
NativeType::USize => {
- let value = self.usize_value;
- let local_value: v8::Local<v8::Value> =
- if value > MAX_SAFE_INTEGER as usize {
- v8::BigInt::new_from_u64(scope, value as u64).into()
- } else {
- v8::Number::new(scope, value as f64).into()
- };
- local_value
+ v8::BigInt::new_from_u64(scope, self.usize_value as u64).into()
}
NativeType::ISize => {
- let value = self.isize_value;
- let local_value: v8::Local<v8::Value> =
- if !(MIN_SAFE_INTEGER..=MAX_SAFE_INTEGER).contains(&value) {
- v8::BigInt::new_from_i64(scope, self.isize_value as i64).into()
- } else {
- v8::Number::new(scope, value as f64).into()
- };
- local_value
+ v8::BigInt::new_from_i64(scope, self.isize_value as i64).into()
}
NativeType::F32 => v8::Number::new(scope, self.f32_value as f64).into(),
NativeType::F64 => v8::Number::new(scope, self.f64_value).into(),