diff options
author | Andreu Botella <andreu@andreubotella.com> | 2022-07-11 17:27:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-11 17:27:33 +0200 |
commit | 018ad9b3a4f2e5c8597274f61262c6035bdb560d (patch) | |
tree | 5dba5fd5a9a9e8fd818532b66ead5c5721e32508 /ext/web/message_port.rs | |
parent | 83c9714fb2f401e82a6c2e784a43130818e8282d (diff) |
chore(web, worker): Use `DetachedBuffer` for `postMessage` ops (#15133)
This commit uses `DetachedBuffer` instead of `ZeroCopyBuf` in the ops
that back `Worker.prototype.postMessage` and
`MessagePort.prototype.postMessage`. This is done because the
serialized buffer is then copied to the destination isolate, even
though it is internal to runtime code and not used for anything else,
so detaching it and transferring it instead saves an unnecessary copy.
Diffstat (limited to 'ext/web/message_port.rs')
-rw-r--r-- | ext/web/message_port.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/ext/web/message_port.rs b/ext/web/message_port.rs index 06f7e3c52..48c899216 100644 --- a/ext/web/message_port.rs +++ b/ext/web/message_port.rs @@ -6,7 +6,7 @@ use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::op; -use deno_core::ZeroCopyBuf; +use deno_core::DetachedBuffer; use deno_core::{CancelFuture, Resource}; use deno_core::{CancelHandle, OpState}; use deno_core::{RcRef, ResourceId}; @@ -21,7 +21,7 @@ enum Transferable { ArrayBuffer(u32), } -type MessagePortMessage = (Vec<u8>, Vec<Transferable>); +type MessagePortMessage = (DetachedBuffer, Vec<Transferable>); pub struct MessagePort { rx: RefCell<UnboundedReceiver<MessagePortMessage>>, @@ -40,7 +40,7 @@ impl MessagePort { // Swallow the failed to send error. It means the channel was disentangled, // but not cleaned up. if let Some(tx) = &*self.tx.borrow() { - tx.send((data.data.to_vec(), transferables)).ok(); + tx.send((data.data, transferables)).ok(); } Ok(()) @@ -59,7 +59,7 @@ impl MessagePort { let js_transferables = serialize_transferables(&mut state.borrow_mut(), transferables); return Ok(Some(JsMessageData { - data: ZeroCopyBuf::from(data), + data, transferables: js_transferables, })); } @@ -182,7 +182,7 @@ fn serialize_transferables( #[derive(Deserialize, Serialize)] pub struct JsMessageData { - data: ZeroCopyBuf, + data: DetachedBuffer, transferables: Vec<JsTransferable>, } |