diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-07-05 22:45:10 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-05 22:45:10 +0530 |
commit | 57fae55d822f5aae52ea93d0e55155bc9c12672f (patch) | |
tree | 1717428419a91d702b1bc690aa86880f2f917b89 /ext/node/polyfills/internal_binding | |
parent | 2e7bcb422d593248cfb654ee1b7ffd341c83353c (diff) |
perf(ext/node): optimize net streams (#19678)
~4.5x improvement in `npm:ws` echo benchmark:
```
$ ./load_test 10 0.0.0.0 8080 0 0
Using message size of 20 bytes
Running benchmark now...
Msg/sec: 101083.750000
Msg/sec: 103606.000000
^C
$ ./load_test 10 0.0.0.0 8080 0 0
Using message size of 20 bytes
Running benchmark now...
Msg/sec: 24906.750000
Msg/sec: 28478.000000
^C
```
Diffstat (limited to 'ext/node/polyfills/internal_binding')
-rw-r--r-- | ext/node/polyfills/internal_binding/stream_wrap.ts | 4 | ||||
-rw-r--r-- | ext/node/polyfills/internal_binding/types.ts | 3 |
2 files changed, 5 insertions, 2 deletions
diff --git a/ext/node/polyfills/internal_binding/stream_wrap.ts b/ext/node/polyfills/internal_binding/stream_wrap.ts index 4d2c8c4d7..27870b20b 100644 --- a/ext/node/polyfills/internal_binding/stream_wrap.ts +++ b/ext/node/polyfills/internal_binding/stream_wrap.ts @@ -279,7 +279,7 @@ export class LibuvStreamWrap extends HandleWrap { /** Internal method for reading from the attached stream. */ async #read() { - let buf = new Uint8Array(SUGGESTED_SIZE); + let buf = BUF; let nread: number | null; try { @@ -375,3 +375,5 @@ export class LibuvStreamWrap extends HandleWrap { return; } } + +const BUF = new Uint8Array(SUGGESTED_SIZE); diff --git a/ext/node/polyfills/internal_binding/types.ts b/ext/node/polyfills/internal_binding/types.ts index 28cf395f8..fe697f194 100644 --- a/ext/node/polyfills/internal_binding/types.ts +++ b/ext/node/polyfills/internal_binding/types.ts @@ -25,6 +25,7 @@ // deno-lint-ignore-file prefer-primordials const { core } = globalThis.__bootstrap; +const { ops } = core; // https://tc39.es/ecma262/#sec-object.prototype.tostring const _toString = Object.prototype.toString; @@ -89,7 +90,7 @@ function isObjectLike( export function isAnyArrayBuffer( value: unknown, ): value is ArrayBuffer | SharedArrayBuffer { - return isArrayBuffer(value) || isSharedArrayBuffer(value); + return ops.op_is_any_arraybuffer(value); } export function isArgumentsObject(value: unknown): value is IArguments { |