diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-03-30 22:00:19 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-30 16:30:19 +0000 |
commit | 30ee8465882d27499344062df05b05af99075c31 (patch) | |
tree | a403f7ff147cf9b030f5cf26529ef672024455fa /ext/websocket/lib.rs | |
parent | c4f82cab31d1ec09b2bce1f0155f92c7d7bd50e0 (diff) |
perf(ext/websocket): special op for sending binary data frames (#18506)
Easy perf win by avoiding deserializing `SendValue` through serde_v8.
| name | avg msg/sec/core |
| --- | --- |
| deno_main | `127820.750000` |
| deno_this | `140079.000000` |
Diffstat (limited to 'ext/websocket/lib.rs')
-rw-r--r-- | ext/websocket/lib.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs index 8eac3e350..8d3cb20d2 100644 --- a/ext/websocket/lib.rs +++ b/ext/websocket/lib.rs @@ -403,6 +403,20 @@ pub enum SendValue { } #[op] +pub async fn op_ws_send_binary( + state: Rc<RefCell<OpState>>, + rid: ResourceId, + data: ZeroCopyBuf, +) -> Result<(), AnyError> { + let resource = state + .borrow_mut() + .resource_table + .get::<WsStreamResource>(rid)?; + resource.send(Message::Binary(data.to_vec())).await?; + Ok(()) +} + +#[op] pub async fn op_ws_send_text( state: Rc<RefCell<OpState>>, rid: ResourceId, @@ -518,6 +532,7 @@ deno_core::extension!(deno_websocket, op_ws_send, op_ws_close, op_ws_next_event, + op_ws_send_binary, op_ws_send_text, ], esm = [ "01_websocket.js", "02_websocketstream.js" ], |