1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00
denoland-deno/core/bindings.js
Matt Mastracci bb1f5e4262
perf(core): async op pseudo-codegen and performance work (#18887)
Performance:

```
async_ops.js: 760k -> 1030k (!)
async_ops_deferred.js: 730k -> 770k
Deno.serve bench: 118k -> 124k
WS test w/ third_party/prebuilt/mac/load_test 100 localhost 8000 0 0: unchanged

Startup time: approx 0.5ms slower (13.7 -> 14.2ms)
```
2023-04-30 08:50:24 +00:00

49 lines
1.1 KiB
JavaScript

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
if (!globalThis.Deno) {
globalThis.Deno = {
core: {
ops: {},
asyncOps: {},
},
};
}
Deno.__op__console = function (callConsole, console) {
Deno.core.callConsole = callConsole;
Deno.core.console = console;
};
Deno.__op__registerOp = function (isAsync, op, opName) {
const core = Deno.core;
if (isAsync) {
if (core.ops[opName] !== undefined) {
return;
}
core.asyncOps[opName] = op;
core.ops[opName] = function (...args) {
if (this !== core.ops) {
// deno-lint-ignore prefer-primordials
throw new Error(
"An async stub cannot be separated from Deno.core.ops. Use ???",
);
}
return core.asyncStub(opName, args);
};
} else {
core.ops[opName] = op;
}
};
Deno.__op__unregisterOp = function (isAsync, opName) {
if (isAsync) {
delete Deno.core.asyncOps[opName];
}
delete Deno.core.ops[opName];
};
Deno.__op__cleanup = function () {
delete Deno.__op__console;
delete Deno.__op__registerOp;
delete Deno.__op__unregisterOp;
delete Deno.__op__cleanup;
};