⚡️ Speed up function data_contains_sv_detections by 26%
#779
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.
📄 26% (0.26x) speedup for
data_contains_sv_detectionsininference/core/workflows/execution_engine/v1/executor/output_constructor.py⏱️ Runtime :
2.16 milliseconds→1.71 milliseconds(best of46runs)📝 Explanation and details
The optimized code replaces inefficient set-based collection with early-return logic, delivering a 26% speedup.
Key optimizations applied:
Eliminated unnecessary set operations: The original code created a
set(), added boolean results to it, then checked ifTrue in result. The optimized version directly returnsTrueon the first positive match, avoiding set allocation and membership operations entirely.Early termination: Instead of collecting all recursive results, the function now returns immediately when it finds the first
sv.Detectionsinstance, significantly reducing unnecessary recursive calls.Why this leads to speedup:
Impact on workloads:
Based on the function references,
data_contains_sv_detectionsis called in workflow output construction loops where it processes batch data. The optimization is particularly beneficial because:Test case performance patterns:
The optimization maintains identical functionality while being more efficient for the common case where detections exist and can be found without exhaustive search.
✅ Correctness verification report:
⚙️ Existing Unit Tests and Runtime
workflows/unit_tests/execution_engine/executor/test_output_constructor.py::test_data_contains_sv_detections_when_no_sv_detections_providedworkflows/unit_tests/execution_engine/executor/test_output_constructor.py::test_data_contains_sv_detections_when_sv_detections_provided_directlyworkflows/unit_tests/execution_engine/executor/test_output_constructor.py::test_data_contains_sv_detections_when_sv_detections_provided_in_dict🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-data_contains_sv_detections-miqipb1qand push.