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:
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user