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

wip #936

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

wip #936

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ops/op2/dispatch_fast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,10 @@ fn map_v8_fastcall_arg_to_arg(
}
}
Arg::String(Strings::String) => {
quote!(let #arg_ident = deno_core::_ops::to_string_ptr(unsafe { &mut *#arg_ident });)
*needs_scope = true;
quote!(
let #arg_ident = deno_core::_ops::to_string(&mut #scope, &*#arg_ident);
)
}
Arg::String(Strings::CowStr) => {
quote! {
Expand Down Expand Up @@ -877,12 +880,14 @@ fn map_arg_to_v8_fastcall_type(
// Ref strings that are one byte internally may be passed as a SeqOneByteString,
// which gives us a FastApiOneByteString.
Arg::String(Strings::RefStr) => V8FastCallType::SeqOneByteString,
// Owned strings can be fast, but we'll have to copy them.
Arg::String(Strings::String) => V8FastCallType::SeqOneByteString,
// Cow strings can be fast, but may require copying
Arg::String(Strings::CowStr) => V8FastCallType::SeqOneByteString,
// Cow byte strings can be fast and don't require copying
Arg::String(Strings::CowByte) => V8FastCallType::SeqOneByteString,
// Strings are passed to fast calls as V8String, and are then extracted
// using v8::ValueView. For one byte ASCII strings we can avoid copying. For
// other strings we always have to copy / rewrite.
Arg::String(Strings::String) => V8FastCallType::V8Value,
Arg::External(..) => V8FastCallType::Pointer,
Arg::CppGcResource(..) => V8FastCallType::V8Value,
Arg::OptionCppGcResource(..) => V8FastCallType::V8Value,
Expand Down
31 changes: 31 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

const hexSliceLookupTable = (function () {
const alphabet = "0123456789abcdef";
const table = new Array(256);
for (let i = 0; i < 16; ++i) {
const i16 = i * 16;
for (let j = 0; j < 16; ++j) {
table[i16 + j] = alphabet[i] + alphabet[j];
}
}
return table;
})();

function generateId(size: number) {
let out = "";
for (let i = 0; i < size / 4; i += 1) {
const r32 = (Math.random() * 2 ** 32) >>> 0;
out += hexSliceLookupTable[(r32 >> 24) & 0xff];
out += hexSliceLookupTable[(r32 >> 16) & 0xff];
out += hexSliceLookupTable[(r32 >> 8) & 0xff];
out += hexSliceLookupTable[r32 & 0xff];
}
return out;
}


const start = Date.now();
while (start + 1000 > Date.now()) {
const id = generateId(16);
op_fast(id);
}
1 change: 1 addition & 0 deletions testing/checkin/runner/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ deno_core::extension!(
ops::op_stats_dump,
ops::op_stats_delete,
ops::op_nop_generic<P>,
ops::op_fast,
ops_io::op_pipe_create,
ops_io::op_file_open,
ops_async::op_task_submit,
Expand Down
13 changes: 13 additions & 0 deletions testing/checkin/runner/ops.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::str;
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use std::cell::RefCell;
use std::rc::Rc;
Expand All @@ -8,6 +9,7 @@ use deno_core::stats::RuntimeActivitySnapshot;
use deno_core::stats::RuntimeActivityStats;
use deno_core::stats::RuntimeActivityStatsFactory;
use deno_core::stats::RuntimeActivityStatsFilter;
use deno_core::v8;
use deno_core::GarbageCollected;
use deno_core::OpDecl;
use deno_core::OpState;
Expand All @@ -21,6 +23,17 @@ pub fn op_log_debug(#[string] s: &str) {
println!("{s}");
}

#[op2(fast)]
pub fn op_fast(scope: &mut v8::HandleScope<'_>, s: v8::Local<'_, v8::Value>) {
let x = v8::ValueView::new(scope, s.cast());
match x.data() {
v8::ValueViewData::OneByte(s) => {
let str = str::from_utf8(s).unwrap();
}
v8::ValueViewData::TwoByte(_) => {}
};
}

#[op2(fast)]
pub fn op_log_info(#[state] output: &mut Output, #[string] s: String) {
println!("{s}");
Expand Down
3 changes: 3 additions & 0 deletions testing/checkin/runtime/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import {
op_error_context_async,
op_error_context_sync,
op_error_custom_sync,
op_fast,
} from "ext:core/ops";

globalThis.op_fast = op_fast;

export async function asyncThrow(kind: "lazy" | "eager" | "deferred") {
const op = {
lazy: op_async_throw_error_lazy,
Expand Down
Loading