Improve performance of generate diffs of state change events (#124601)
dict comps are inlined in cpython 3.12+pull/124620/head
parent
0591b5e47b
commit
76ebb0df08
|
@ -224,9 +224,12 @@ def _state_diff_event(
|
|||
if (old_attributes := old_state.attributes) != (
|
||||
new_attributes := new_state.attributes
|
||||
):
|
||||
for key, value in new_attributes.items():
|
||||
if old_attributes.get(key) != value:
|
||||
additions.setdefault(COMPRESSED_STATE_ATTRIBUTES, {})[key] = value
|
||||
if added := {
|
||||
key: value
|
||||
for key, value in new_attributes.items()
|
||||
if key not in old_attributes or old_attributes[key] != value
|
||||
}:
|
||||
additions[COMPRESSED_STATE_ATTRIBUTES] = added
|
||||
if removed := old_attributes.keys() - new_attributes:
|
||||
# sets are not JSON serializable by default so we convert to list
|
||||
# here if there are any values to avoid jumping into the json_encoder_default
|
||||
|
|
Loading…
Reference in New Issue