Repository navigation
Optimize Signature.clone options copying with an immutable fast path - #10163
AsymptotaX wants to merge 11 commits into
Conversation
Nusnus
left a comment
There was a problem hiding this comment.
Interesting PR.. lets see how the CI is going..
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10163 +/- ##
==========================================
- Coverage 88.22% 88.22% -0.01%
==========================================
Files 153 153
Lines 19559 19566 +7
Branches 2246 2248 +2
==========================================
+ Hits 17256 17262 +6
Misses 2005 2005
- Partials 298 299 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
Pull request overview
This PR optimizes Signature.clone() — a hot path in large canvas workflows (group/chord) — by avoiding deepcopy() when task options contain only immutable scalar values. A new helper _clone_options() applies a shallow copy in the scalar-only case and falls back to deepcopy otherwise, preserving correctness for mutable structures like link, link_error, chord, and stamped_headers.
Changes:
- Added
_FAST_PATH_IMMUTABLE_TYPEStuple and_clone_options()helper incelery/canvas.py. - Replaced
deepcopy(opts)with_clone_options(opts)inSignature.clone(). - Added two targeted unit tests covering the fast-path (scalar options) and fallback (mutable options) behaviors.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
celery/canvas.py |
Adds _FAST_PATH_IMMUTABLE_TYPES constant and _clone_options() helper; wires it into Signature.clone() in place of the direct deepcopy(opts) call. |
t/unit/tasks/test_canvas.py |
Adds two tests verifying that scalar options are independently copied and that mutable options are still deep-copied on clone. |
Co-authored-by: Copilot <[email protected]>
34baff5 to
49c1f43
Compare
…imize-clone-options # Conflicts: # celery/canvas.py
auvipy
left a comment
There was a problem hiding this comment.
should we consider adding an Integration test? or it is already covered?
…imize-clone-options
I think this is already sufficiently covered at the unit level. Since the change is internal to |
|
@ChickenBenny please feel free to try it and share your views |
|
@aurangzaib048 can you please try and review it |
Description
This PR optimizes a hot path in Signature.clone() by avoiding deepcopy() when task options contain only immutable scalar values.
What changed
if all option values are immutable scalars (str, bytes, int, float, bool, None), use dict.copy() otherwise keep the existing deepcopy() behavior
Why
Large canvas workflows (group/chord) call clone() heavily during publish. This reduces copy overhead on the common scalar-only options case while preserving safety for mutable structures.
benchmark