summaryrefslogtreecommitdiff
path: root/ext/web/lib.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-03-05 13:30:22 +0530
committerGitHub <noreply@github.com>2023-03-05 13:30:22 +0530
commit0910be4d64272be6774b8b3d44852737e8c53ad4 (patch)
treeef8dcbf2e5cf0c8940512923dec016dd2a30c762 /ext/web/lib.rs
parent888ceac7fdc6e9b96d860f183dd2f31df3f3d601 (diff)
feat(ops): relational ops (#18023)
Join two independent ops into one. A fast impl of one + a slow callback of another. Here's an example showing optimized paths for latin-1 via fast call and the next-best fallback using V8 apis. ```rust #[op(v8)] fn op_encoding_encode_into_fallback( scope: &mut v8::HandleScope, input: serde_v8::Value, // ... #[op(fast, slow = op_encoding_encode_into_fallback)] fn op_encoding_encode_into( input: Cow<'_, str>, // ... ``` Benchmark results of the fallback path: ``` time target/release/deno run -A --unstable ./cli/tests/testdata/benches/text_encoder_into_perf.js ________________________________________________________ Executed in 70.90 millis fish external usr time 57.76 millis 0.23 millis 57.53 millis sys time 17.02 millis 1.28 millis 15.74 millis target/release/deno_main run -A --unstable ./cli/tests/testdata/benches/text_encoder_into_perf.js ________________________________________________________ Executed in 154.00 millis fish external usr time 67.14 millis 0.26 millis 66.88 millis sys time 38.82 millis 1.47 millis 37.35 millis ```
Diffstat (limited to 'ext/web/lib.rs')
-rw-r--r--ext/web/lib.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/ext/web/lib.rs b/ext/web/lib.rs
index 2f59636fe..76095810e 100644
--- a/ext/web/lib.rs
+++ b/ext/web/lib.rs
@@ -350,7 +350,28 @@ impl Resource for TextDecoderResource {
}
}
-#[op]
+#[op(v8)]
+fn op_encoding_encode_into_fallback(
+ scope: &mut v8::HandleScope,
+ input: serde_v8::Value,
+ buffer: &mut [u8],
+ out_buf: &mut [u32],
+) -> Result<(), AnyError> {
+ let s = v8::Local::<v8::String>::try_from(input.v8_value)?;
+
+ let mut nchars = 0;
+ out_buf[1] = s.write_utf8(
+ scope,
+ buffer,
+ Some(&mut nchars),
+ v8::WriteOptions::NO_NULL_TERMINATION
+ | v8::WriteOptions::REPLACE_INVALID_UTF8,
+ ) as u32;
+ out_buf[0] = nchars as u32;
+ Ok(())
+}
+
+#[op(fast, slow = op_encoding_encode_into_fallback)]
fn op_encoding_encode_into(
input: Cow<'_, str>,
buffer: &mut [u8],