diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-06-08 09:32:08 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-08 09:32:08 -0600 |
commit | 976c38104569182ba41d9351a108e673f63ffb98 (patch) | |
tree | 9bb0ce756a701febdbfdac18e49891c4d0b58fa8 /ext/websocket/02_websocketstream.js | |
parent | f35161d3c549c46309ddfbe286ed3f9507076ccd (diff) |
perf(ext/websocket): Reduce GC pressure & monomorpize op_ws_next_event (#19405)
Reduce the GC pressure from the websocket event method by splitting it
into an event getter and a buffer getter.
Before:
165.9k msg/sec
After:
169.9k msg/sec
Diffstat (limited to 'ext/websocket/02_websocketstream.js')
-rw-r--r-- | ext/websocket/02_websocketstream.js | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/ext/websocket/02_websocketstream.js b/ext/websocket/02_websocketstream.js index be1001eb6..068fa3e1b 100644 --- a/ext/websocket/02_websocketstream.js +++ b/ext/websocket/02_websocketstream.js @@ -37,6 +37,9 @@ const { op_ws_send_text_async, op_ws_send_binary_async, op_ws_next_event, + op_ws_get_buffer, + op_ws_get_buffer_as_string, + op_ws_get_error, op_ws_create, op_ws_close, } = core.ensureFastOps(); @@ -177,7 +180,7 @@ class WebSocketStream { PromisePrototypeThen( (async () => { while (true) { - const { 0: kind } = await op_ws_next_event(create.rid); + const kind = await op_ws_next_event(create.rid); if (kind > 5) { /* close */ @@ -239,14 +242,16 @@ class WebSocketStream { }, }); const pull = async (controller) => { - const { 0: kind, 1: value } = await op_ws_next_event(this[_rid]); + const kind = await op_ws_next_event(this[_rid]); switch (kind) { case 0: - case 1: { /* string */ + controller.enqueue(op_ws_get_buffer_as_string(this[_rid])); + break; + case 1: { /* binary */ - controller.enqueue(value); + controller.enqueue(op_ws_get_buffer(this[_rid])); break; } case 2: { @@ -255,7 +260,7 @@ class WebSocketStream { } case 3: { /* error */ - const err = new Error(value); + const err = new Error(op_ws_get_error(this[_rid])); this[_closed].reject(err); controller.error(err); core.tryClose(this[_rid]); @@ -271,7 +276,7 @@ class WebSocketStream { /* close */ this[_closed].resolve({ code: kind, - reason: value, + reason: op_ws_get_error(this[_rid]), }); core.tryClose(this[_rid]); break; @@ -289,7 +294,7 @@ class WebSocketStream { return pull(controller); } - this[_closed].resolve(value); + this[_closed].resolve(op_ws_get_error(this[_rid])); core.tryClose(this[_rid]); } }; |