Skip to content

Commit

Permalink
Use bytes join fast path for large states payload (#110694)
Browse files Browse the repository at this point in the history
b"".join has a fast path for when there are more than two bytes-strings
to combine

https://github.com/python/cpython/blob/f383ca1a6fa1a2a83c8c1a0e56cf997c77fa2893/Objects/stringlib/join.h#L123
  • Loading branch information
bdraco authored Feb 16, 2024
1 parent 37897ee commit 9cf4588
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def get(self, request: web.Request) -> web.Response:
if entity_perm(state.entity_id, "read")
)
response = web.Response(
body=b"[" + b",".join(states) + b"]",
body=b"".join((b"[", b",".join(states), b"]")),
content_type=CONTENT_TYPE_JSON,
zlib_executor_size=32768,
)
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/websocket_api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ def _send_handle_get_states_response(
) -> None:
"""Send handle get states response."""
connection.send_message(
construct_result_message(msg_id, b"[" + b",".join(serialized_states) + b"]")
construct_result_message(
msg_id, b"".join((b"[", b",".join(serialized_states), b"]"))
)
)


Expand Down

0 comments on commit 9cf4588

Please sign in to comment.