Use bytes join fast path for large states payload (#110694)

b"".join has a fast path for when there are more than two bytes-strings
to combine

f383ca1a6f/Objects/stringlib/join.h (L123)
This commit is contained in:
J. Nick Koston 2024-02-16 00:58:11 -06:00 committed by GitHub
parent 37897ee384
commit 9cf45882a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -222,7 +222,7 @@ class APIStatesView(HomeAssistantView):
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,
)

View File

@ -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"]"))
)
)