Serialize websocket event message once (#40453)

Since most of the json serialize work for the websocket was done
multiple times for the same message, we can avoid the overhead
of serializing the same message many times (once per websocket
client) with a cache.
This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-09-22 08:47:04 -05:00
1 parent d82b97fbe1
commit f0f817c361
5 files changed
+120 -32

No files matched your search

@@ -77,7 +77,7 @@ def handle_subscribe_events(hass, connection, msg):
):
return
connection.send_message(messages.event_message(msg["id"], event))
connection.send_message(messages.cached_event_message(msg["id"], event))
else:
@@ -87,7 +87,7 @@ def handle_subscribe_events(hass, connection, msg):
if event.event_type == EVENT_TIME_CHANGED:
return
connection.send_message(messages.event_message(msg["id"], event.as_dict()))
connection.send_message(messages.cached_event_message(msg["id"], event))
connection.subscriptions[msg["id"]] = hass.bus.async_listen(
event_type, forward_events