1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 16:42:21 -05:00

refactor(core): ensureFastOps is an op-generating proxy (#19377)

Startup benchmark shows no changes (within 1ms, identical system/user
times).
This commit is contained in:
Matt Mastracci 2023-06-06 03:01:28 -06:00 committed by GitHub
parent 5c55f2b4fb
commit 0bbdbace02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 26 additions and 82 deletions

View file

@ -22,6 +22,7 @@
PromiseReject, PromiseReject,
PromiseResolve, PromiseResolve,
PromisePrototypeThen, PromisePrototypeThen,
Proxy,
RangeError, RangeError,
ReferenceError, ReferenceError,
ReflectHas, ReflectHas,
@ -762,19 +763,19 @@ for (let i = 0; i < 10; i++) {
setUpAsyncStub(opName); setUpAsyncStub(opName);
} }
function generateAsyncOpHandler(/* opNames... */) { function ensureFastOps() {
const fastOps = {}; return new Proxy({}, {
for (const opName of new SafeArrayIterator(arguments)) { get(_target, opName) {
if (ops[opName] === undefined) { if (ops[opName] === undefined) {
throw new Error(`Unknown or disabled op '${opName}'`); throw new Error(`Unknown or disabled op '${opName}'`);
} }
if (asyncOps[opName] !== undefined) { if (asyncOps[opName] !== undefined) {
fastOps[opName] = setUpAsyncStub(opName); return setUpAsyncStub(opName);
} else { } else {
fastOps[opName] = ops[opName]; return ops[opName];
} }
} },
return fastOps; });
} }
const { const {
@ -787,22 +788,12 @@ for (let i = 0; i < 10; i++) {
op_read_sync: readSync, op_read_sync: readSync,
op_write_sync: writeSync, op_write_sync: writeSync,
op_shutdown: shutdown, op_shutdown: shutdown,
} = generateAsyncOpHandler( } = ensureFastOps();
"op_close",
"op_try_close",
"op_read",
"op_read_all",
"op_write",
"op_write_all",
"op_read_sync",
"op_write_sync",
"op_shutdown",
);
// Extra Deno.core.* exports // Extra Deno.core.* exports
const core = ObjectAssign(globalThis.Deno.core, { const core = ObjectAssign(globalThis.Deno.core, {
asyncStub, asyncStub,
generateAsyncOpHandler, ensureFastOps,
opAsync, opAsync,
resources, resources,
metrics, metrics,

View file

@ -9,10 +9,7 @@ const { op_listen } = Deno.core.ops;
const { const {
op_accept, op_accept,
op_read_socket, op_read_socket,
} = Deno.core.generateAsyncOpHandler( } = Deno.core.ensureFastOps();
"op_accept",
"op_read_socket",
);
const requestBuf = new Uint8Array(64 * 1024); const requestBuf = new Uint8Array(64 * 1024);
const responseBuf = new Uint8Array( const responseBuf = new Uint8Array(

View file

@ -2852,7 +2852,7 @@ pub mod tests {
.execute_script_static( .execute_script_static(
"filename.js", "filename.js",
r#" r#"
const { op_test } = Deno.core.generateAsyncOpHandler("op_test"); const { op_test } = Deno.core.ensureFastOps();
let zero_copy_a = new Uint8Array([0]); let zero_copy_a = new Uint8Array([0]);
op_test(null, zero_copy_a); op_test(null, zero_copy_a);
"#, "#,
@ -4942,7 +4942,7 @@ Deno.core.opAsync("op_async_serialize_object_with_numbers_as_keys", {
throw new Error(); throw new Error();
} }
const { op_test_async } = Deno.core.generateAsyncOpHandler("op_test_async"); const { op_test_async } = Deno.core.ensureFastOps();
if (op_test_async.name !== "op_test_async") { if (op_test_async.name !== "op_test_async") {
throw new Error(); throw new Error();
} }

View file

@ -10,13 +10,7 @@ const {
op_fs_truncate_async, op_fs_truncate_async,
op_fs_link_async, op_fs_link_async,
op_fs_flock_async, op_fs_flock_async,
} = Deno.core.generateAsyncOpHandler( } = Deno.core.ensureFastOps();
"op_fs_chmod_async",
"op_fs_ftruncate_async",
"op_fs_truncate_async",
"op_fs_link_async",
"op_fs_flock_async",
);
const primordials = globalThis.__bootstrap.primordials; const primordials = globalThis.__bootstrap.primordials;
const { const {
ArrayPrototypeFilter, ArrayPrototypeFilter,

View file

@ -70,25 +70,7 @@ const {
op_http_upgrade_websocket_next, op_http_upgrade_websocket_next,
op_http_try_wait, op_http_try_wait,
op_http_wait, op_http_wait,
} = core.generateAsyncOpHandler( } = core.ensureFastOps();
"op_http_get_request_headers",
"op_http_get_request_method_and_url",
"op_http_read_request_body",
"op_http_serve",
"op_http_serve_on",
"op_http_set_promise_complete",
"op_http_set_response_body_bytes",
"op_http_set_response_body_resource",
"op_http_set_response_body_stream",
"op_http_set_response_body_text",
"op_http_set_response_header",
"op_http_set_response_headers",
"op_http_set_response_trailers",
"op_http_upgrade_raw",
"op_http_upgrade_websocket_next",
"op_http_try_wait",
"op_http_wait",
);
const _upgraded = Symbol("_upgraded"); const _upgraded = Symbol("_upgraded");
function internalServerError() { function internalServerError() {

View file

@ -6,7 +6,7 @@ const core = globalThis.Deno.core;
const internals = globalThis.__bootstrap.internals; const internals = globalThis.__bootstrap.internals;
const primordials = globalThis.__bootstrap.primordials; const primordials = globalThis.__bootstrap.primordials;
const { BadResourcePrototype, InterruptedPrototype, ops } = core; const { BadResourcePrototype, InterruptedPrototype, ops } = core;
const { op_http_write } = Deno.core.generateAsyncOpHandler("op_http_write"); const { op_http_write } = Deno.core.ensureFastOps();
import * as webidl from "ext:deno_webidl/00_webidl.js"; import * as webidl from "ext:deno_webidl/00_webidl.js";
import { InnerBody } from "ext:deno_fetch/22_body.js"; import { InnerBody } from "ext:deno_fetch/22_body.js";
import { Event, setEventTargetData } from "ext:deno_web/02_event.js"; import { Event, setEventTargetData } from "ext:deno_web/02_event.js";

View file

@ -37,11 +37,7 @@ const {
op_node_gen_prime_async, op_node_gen_prime_async,
op_node_check_prime_bytes_async, op_node_check_prime_bytes_async,
op_node_check_prime_async, op_node_check_prime_async,
} = Deno.core.generateAsyncOpHandler( } = Deno.core.ensureFastOps();
"op_node_gen_prime_async",
"op_node_check_prime_bytes_async",
"op_node_check_prime_async",
);
export type LargeNumberLike = export type LargeNumberLike =
| ArrayBufferView | ArrayBufferView

View file

@ -27,10 +27,7 @@ const {
import * as webidl from "ext:deno_webidl/00_webidl.js"; import * as webidl from "ext:deno_webidl/00_webidl.js";
import { reportException } from "ext:deno_web/02_event.js"; import { reportException } from "ext:deno_web/02_event.js";
import { assert } from "ext:deno_web/00_infra.js"; import { assert } from "ext:deno_web/00_infra.js";
const { op_sleep, op_void_async_deferred } = core.generateAsyncOpHandler( const { op_sleep, op_void_async_deferred } = core.ensureFastOps();
"op_sleep",
"op_void_async_deferred",
);
const hrU8 = new Uint8Array(8); const hrU8 = new Uint8Array(8);
const hr = new Uint32Array(TypedArrayPrototypeGetBuffer(hrU8)); const hr = new Uint32Array(TypedArrayPrototypeGetBuffer(hrU8));

View file

@ -57,14 +57,7 @@ const {
op_ws_send_text, op_ws_send_text,
op_ws_next_event, op_ws_next_event,
op_ws_send_ping, op_ws_send_ping,
} = core.generateAsyncOpHandler( } = core.ensureFastOps();
"op_ws_create",
"op_ws_close",
"op_ws_send_binary",
"op_ws_send_text",
"op_ws_next_event",
"op_ws_send_ping",
);
webidl.converters["sequence<DOMString> or DOMString"] = ( webidl.converters["sequence<DOMString> or DOMString"] = (
V, V,

View file

@ -39,13 +39,7 @@ const {
op_ws_next_event, op_ws_next_event,
op_ws_create, op_ws_create,
op_ws_close, op_ws_close,
} = core.generateAsyncOpHandler( } = core.ensureFastOps();
"op_ws_send_text",
"op_ws_send_binary",
"op_ws_next_event",
"op_ws_create",
"op_ws_close",
);
webidl.converters.WebSocketStreamOptions = webidl.createDictionaryConverter( webidl.converters.WebSocketStreamOptions = webidl.createDictionaryConverter(
"WebSocketStreamOptions", "WebSocketStreamOptions",