mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Reduce memcpy to coalesce WebSocket messages.
In most cases its faster to avoid making the inner payload and than copying it again into the outer payload.
This commit is contained in:
parent
9f2232fad1
commit
c4133b9972
@ -7,6 +7,7 @@ from collections import deque
|
||||
from collections.abc import Callable, Coroutine
|
||||
import datetime as dt
|
||||
from functools import partial
|
||||
from itertools import chain
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, Any, Final
|
||||
|
||||
@ -162,7 +163,8 @@ class WebSocketHandler:
|
||||
await send_bytes_text(message)
|
||||
continue
|
||||
|
||||
coalesced_messages = b"".join((b"[", b",".join(message_queue), b"]"))
|
||||
messages = tuple(chain.from_iterable((x, b",") for x in message_queue))
|
||||
coalesced_messages = b"".join((b"[", *messages[:-1], b"]"))
|
||||
message_queue.clear()
|
||||
if is_debug_log_enabled():
|
||||
debug("%s: Sending %s", self.description, coalesced_messages)
|
||||
|
Loading…
x
Reference in New Issue
Block a user