Skip to content

Commit daba56f

Browse files
committed
fix: do not copy data before sending over datachannel
The single-arg constructor of `Uint8Array` copies the data from the passed arraylike. This can impact streaming performance in high traffic environments. Instead you can use the three-arg constructor or just pass the Uint8Array through if the arg satisfies that type.
1 parent 5121c31 commit daba56f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/polyfill/RTCDataChannel.ts

+2
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ export default class RTCDataChannel extends EventTarget implements globalThis.RT
180180
this.#dataChannel.sendMessageBinary(new Uint8Array(ab));
181181
}
182182
});
183+
} else if (data instanceof Uint8Array) {
184+
this.#dataChannel.sendMessageBinary(data);
183185
} else {
184186
if (process?.versions?.bun) {
185187
this.#dataChannel.sendMessageBinary(Buffer.from(data));

0 commit comments

Comments
 (0)