⚡️ Speed up method WorkflowHandle.get_update_handle_for
by 16%
#1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📄 16% (0.16x) speedup for
WorkflowHandle.get_update_handle_for
intemporalio/client.py
⏱️ Runtime :
789 microseconds
→681 microseconds
(best of362
runs)📝 Explanation and details
The optimized code achieves a 15% speedup by eliminating method call overhead and reducing attribute lookups through two key optimizations:
1. Eliminated method call indirection in
get_update_handle_for
:self.get_update_handle()
, adding method call overheadWorkflowUpdateHandle
, removing this intermediate call layer2. Pre-computed expressions to avoid repeated evaluations:
workflow_run_id or self._run_id
logic into a local variablerun_id_to_pass
update._defn.ret_type
in local variableret_type
or
expression and attribute access during function argument constructionPerformance characteristics:
The optimizations preserve exact functional behavior while reducing Python bytecode overhead, making them especially valuable for performance-critical workflow handle operations.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-WorkflowHandle.get_update_handle_for-mgh9xylx
and push.