⚡️ Speed up method BlockManifest.describe_outputs by 578%
#624
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.
📄 578% (5.78x) speedup for
BlockManifest.describe_outputsininference/core/workflows/core_steps/models/foundation/stability_ai/outpainting/v1.py⏱️ Runtime :
771 microseconds→114 microseconds(best of145runs)📝 Explanation and details
The optimization introduces pre-computed constant caching by moving the
OutputDefinitionobject creation to module load time as_CACHED_OUTPUTS, rather than constructing it fresh on every method call.Key changes:
_CACHED_OUTPUTS = [OutputDefinition(name="image", kind=[IMAGE_KIND])]describe_outputs()to return the cached list instead of creating new objectsWhy this creates a speedup:
OutputDefinitionobjects and list wrappers on every call, the method simply returns a pre-existing referencePerformance characteristics based on test results:
test_describe_outputs_performance_under_multiple_callsshows 549% speedup when called 1000 times, demonstrating excellent scaling for high-frequency usageThis optimization is particularly effective for workflow blocks that may be queried frequently for their output definitions during pipeline construction or validation phases.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-BlockManifest.describe_outputs-mhbr9mqiand push.