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 2020-09-22 08:47:04 -05:00 committed by GitHub
parent d82b97fbe1
commit f0f817c361
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 120 additions and 32 deletions

View file

@ -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