⚡️ Speed up method BlockManifest.describe_outputs by 633%
#631
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.
📄 633% (6.33x) speedup for
BlockManifest.describe_outputsininference/core/workflows/core_steps/transformations/relative_static_crop/v1.py⏱️ Runtime :
809 microseconds→110 microseconds(best of182runs)📝 Explanation and details
The optimization moves the
OutputDefinitionobject creation from inside thedescribe_outputs()method to a module-level constant_CROPS_OUTPUT. This eliminates the need to create a newOutputDefinitionobject and list every time the method is called.Key changes:
_CROPS_OUTPUTlist containing theOutputDefinitionobject at module import timeWhy this is faster:
OutputDefinitionobject and wraps it in a new list on every method call. The optimized version creates these objects once at import time.OutputDefinitionobject.Test case performance patterns:
The optimization shows consistent 6-17x speedups across all test scenarios, with particularly strong performance in:
This optimization is most effective for workflows that frequently call
describe_outputs(), which is common in workflow execution engines where output definitions are queried repeatedly during pipeline setup and validation.✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-BlockManifest.describe_outputs-mhbw22oiand push.