mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 18:38:33 +00:00
perf(ext/websocket): Make send sync for non-stream websockets (#19376)
No need to go through the async machinery for `send(String | Buffer)` -- we can fire and forget, and then route any send errors into the async call we're already making (`op_ws_next_event`). Early benchmark on MacOS: Before: 155.8k msg/sec After: 166.2k msg/sec (+6.6%) Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
42991017e9
commit
df76a062fa
3 changed files with 93 additions and 59 deletions
|
@ -34,8 +34,8 @@ const {
|
|||
Uint8ArrayPrototype,
|
||||
} = primordials;
|
||||
const {
|
||||
op_ws_send_text,
|
||||
op_ws_send_binary,
|
||||
op_ws_send_text_async,
|
||||
op_ws_send_binary_async,
|
||||
op_ws_next_event,
|
||||
op_ws_create,
|
||||
op_ws_close,
|
||||
|
@ -210,11 +210,11 @@ class WebSocketStream {
|
|||
const writable = new WritableStream({
|
||||
write: async (chunk) => {
|
||||
if (typeof chunk === "string") {
|
||||
await op_ws_send_text(this[_rid], chunk);
|
||||
await op_ws_send_text_async(this[_rid], chunk);
|
||||
} else if (
|
||||
ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, chunk)
|
||||
) {
|
||||
await op_ws_send_binary(this[_rid], chunk);
|
||||
await op_ws_send_binary_async(this[_rid], chunk);
|
||||
} else {
|
||||
throw new TypeError(
|
||||
"A chunk may only be either a string or an Uint8Array",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue