1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-01 19:57:08 +01:00

Avoid walking script variable ChainMap twice when tracing (#173665)

This commit is contained in:
Franck Nijhof
2026-06-15 15:18:28 +02:00
committed by GitHub
parent 9e8af2d098
commit c9d7d842ff
+6 -4
View File
@@ -87,13 +87,15 @@ class TraceElement:
if variables is None:
variables = {}
last_variables = self._last_variables
variables_cv.set(dict(variables))
changed_variables = {
# variables is often a ChainMap which is costly to iterate, so flatten
# it once and reuse the snapshot for both the baseline and the diff.
snapshot = dict(variables)
variables_cv.set(snapshot)
self._variables = {
key: value
for key, value in variables.items()
for key, value in snapshot.items()
if key not in last_variables or last_variables[key] != value
}
self._variables = changed_variables
def as_dict(self) -> dict[str, Any]:
"""Return dictionary version of this TraceElement."""