⚡️ Speed up function strip_version_data by 526% in PR #11859 (workflow-history)#11971
Closed
codeflash-ai[bot] wants to merge 1 commit into
Closed
⚡️ Speed up function strip_version_data by 526% in PR #11859 (workflow-history)#11971codeflash-ai[bot] wants to merge 1 commit into
strip_version_data by 526% in PR #11859 (workflow-history)#11971codeflash-ai[bot] wants to merge 1 commit into
Conversation
The optimization replaces `copy.deepcopy(data)` (which recursively copies the entire flow structure) with `_copy_data_for_stripping`, a helper that shallow-copies only the nested path `nodes → node["data"] → node["data"]["node"] → template → template values` that `remove_api_keys` mutates. Line profiler shows `deepcopy` consumed 94% of runtime at ~4 ms per call; the targeted copy drops this to ~250 µs (51% of new runtime). Because flow data typically contains large immutable subtrees (IDs, metadata) that don't need copying, this selective approach yields a 5.25× speedup with identical semantics—mutations to stripped output never affect the original input.
Contributor
Codecov Report❌ Patch coverage is
❌ Your project status has failed because the head coverage (41.47%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## workflow-history #11971 +/- ##
====================================================
- Coverage 36.45% 33.35% -3.10%
====================================================
Files 1590 1594 +4
Lines 77133 77409 +276
Branches 11740 11740
====================================================
- Hits 28117 25823 -2294
- Misses 47406 49976 +2570
Partials 1610 1610
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Contributor
|
Closing automated codeflash PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
⚡️ This pull request contains optimizations for PR #11859
If you approve this dependent PR, these changes will be merged into the original PR branch
workflow-history.📄 526% (5.26x) speedup for
strip_version_datainsrc/backend/base/langflow/api/v1/flow_version.py⏱️ Runtime :
14.1 milliseconds→2.26 milliseconds(best of150runs)📝 Explanation and details
The optimization replaces
copy.deepcopy(data)(which recursively copies the entire flow structure) with_copy_data_for_stripping, a helper that shallow-copies only the nested pathnodes → node["data"] → node["data"]["node"] → template → template valuesthatremove_api_keysmutates. Line profiler showsdeepcopyconsumed 94% of runtime at ~4 ms per call; the targeted copy drops this to ~250 µs (51% of new runtime). Because flow data typically contains large immutable subtrees (IDs, metadata) that don't need copying, this selective approach yields a 5.25× speedup with identical semantics—mutations to stripped output never affect the original input.✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr11859-2026-03-02T16.24.03and push.