Skip to content

Commit ca22fa1

Browse files
committed
Changed untyped memo to reuse same dict instance.
1 parent 7a823ea commit ca22fa1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

temporalio/worker/_workflow_instance.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def __init__(self, det: WorkflowInstanceDetails) -> None:
219219
self._current_history_size = 0
220220
self._continue_as_new_suggested = False
221221
# Lazily loaded
222-
self._untyped_converted_memo: Optional[Mapping[str, Any]] = None
222+
self._untyped_converted_memo: Optional[MutableMapping[str, Any]] = None
223223
# Handles which are ready to run on the next event loop iteration
224224
self._ready: Deque[asyncio.Handle] = collections.deque()
225225
self._conditions: List[Tuple[Callable[[], bool], asyncio.Future]] = []
@@ -1119,8 +1119,14 @@ def workflow_upsert_memo(self, updates: Mapping[str, Any]) -> None:
11191119
fields[k].CopyFrom(null_payload)
11201120
mut_raw_memo.pop(k, None)
11211121

1122-
# Clearing cached value, will be regenerated on next workflow_memo() call.
1123-
self._untyped_converted_memo = None
1122+
# Keeping deserialized memo dict in sync, if exists
1123+
if self._untyped_converted_memo is not None:
1124+
for k, v in update_payloads.items():
1125+
self._untyped_converted_memo[k] = self._payload_converter.from_payload(
1126+
v
1127+
)
1128+
for k in removals:
1129+
self._untyped_converted_memo.pop(k, None)
11241130

11251131
def workflow_metric_meter(self) -> temporalio.common.MetricMeter:
11261132
# Create if not present, which means using an extern function

0 commit comments

Comments
 (0)