From 8daf893e11845fac40818c7d865eed123389453a Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 30 Mar 2023 21:22:12 +0530 Subject: [PATCH] perf(ext/websocket): special op for sending text data frames (#18507) Similar to #18506 but for Text frames. --- ext/websocket/01_websocket.js | 5 +---- ext/websocket/lib.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ext/websocket/01_websocket.js b/ext/websocket/01_websocket.js index 399b46c52d..d483608d8f 100644 --- a/ext/websocket/01_websocket.js +++ b/ext/websocket/01_websocket.js @@ -325,10 +325,7 @@ class WebSocket extends EventTarget { const d = core.encode(string); this[_bufferedAmount] += d.byteLength; PromisePrototypeThen( - core.opAsync("op_ws_send", this[_rid], { - kind: "text", - value: string, - }), + core.opAsync("op_ws_send_text", this[_rid], string), () => { this[_bufferedAmount] -= d.byteLength; }, diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs index 4195f39b8b..8eac3e3506 100644 --- a/ext/websocket/lib.rs +++ b/ext/websocket/lib.rs @@ -402,6 +402,20 @@ pub enum SendValue { Ping, } +#[op] +pub async fn op_ws_send_text( + state: Rc>, + rid: ResourceId, + data: String, +) -> Result<(), AnyError> { + let resource = state + .borrow_mut() + .resource_table + .get::(rid)?; + resource.send(Message::Text(data)).await?; + Ok(()) +} + #[op] pub async fn op_ws_send( state: Rc>, @@ -504,6 +518,7 @@ deno_core::extension!(deno_websocket, op_ws_send, op_ws_close, op_ws_next_event, + op_ws_send_text, ], esm = [ "01_websocket.js", "02_websocketstream.js" ], options = {