1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

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` |
This commit is contained in:
Divy Srivastava 2023-03-30 22:00:19 +05:30 committed by GitHub
parent c4f82cab31
commit 30ee846588
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View file

@ -301,10 +301,7 @@ class WebSocket extends EventTarget {
const sendTypedArray = (ta) => {
this[_bufferedAmount] += ta.byteLength;
PromisePrototypeThen(
core.opAsync("op_ws_send", this[_rid], {
kind: "binary",
value: ta,
}),
core.opAsync("op_ws_send_binary", this[_rid], ta),
() => {
this[_bufferedAmount] -= ta.byteLength;
},

View file

@ -402,6 +402,20 @@ pub enum SendValue {
Ping,
}
#[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>>,
@ -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" ],