mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
perf(ext/websocket): optimize server websocket js (#19719)
Split from https://github.com/denoland/deno/pull/19686 - timestamp set to 0 for server websocket events. - take fast call path with op_ws_send_binary.
This commit is contained in:
parent
679a0c428c
commit
75d2c045f7
3 changed files with 8 additions and 7 deletions
|
@ -200,7 +200,7 @@ class Event {
|
|||
currentTarget: null,
|
||||
eventPhase: Event.NONE,
|
||||
target: null,
|
||||
timeStamp: DateNow(),
|
||||
timeStamp: 0,
|
||||
};
|
||||
// TODO(@littledivy): Not spec compliant but performance is hurt badly
|
||||
// for users of `_skipInternalInit`.
|
||||
|
|
|
@ -322,7 +322,12 @@ class WebSocket extends EventTarget {
|
|||
throw new DOMException("readyState not OPEN", "InvalidStateError");
|
||||
}
|
||||
|
||||
if (ObjectPrototypeIsPrototypeOf(BlobPrototype, data)) {
|
||||
if (ArrayBufferIsView(data)) {
|
||||
op_ws_send_binary(this[_rid], data);
|
||||
} else if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, data)) {
|
||||
// deno-lint-ignore prefer-primordials
|
||||
op_ws_send_binary(this[_rid], new Uint8Array(data));
|
||||
} else if (ObjectPrototypeIsPrototypeOf(BlobPrototype, data)) {
|
||||
PromisePrototypeThen(
|
||||
// deno-lint-ignore prefer-primordials
|
||||
data.slice().arrayBuffer(),
|
||||
|
@ -332,10 +337,6 @@ class WebSocket extends EventTarget {
|
|||
new DataView(ab),
|
||||
),
|
||||
);
|
||||
} else if (ArrayBufferIsView(data)) {
|
||||
op_ws_send_binary(this[_rid], data);
|
||||
} else if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, data)) {
|
||||
op_ws_send_binary(this[_rid], data);
|
||||
} else {
|
||||
const string = String(data);
|
||||
op_ws_send_text(
|
||||
|
|
|
@ -407,7 +407,7 @@ pub fn ws_create_server_stream(
|
|||
}
|
||||
|
||||
#[op(fast)]
|
||||
pub fn op_ws_send_binary(state: &mut OpState, rid: ResourceId, data: JsBuffer) {
|
||||
pub fn op_ws_send_binary(state: &mut OpState, rid: ResourceId, data: &[u8]) {
|
||||
let resource = state.resource_table.get::<ServerWebSocket>(rid).unwrap();
|
||||
let data = data.to_vec();
|
||||
let len = data.len();
|
||||
|
|
Loading…
Reference in a new issue