From d75ade61c68b671078934b744095a7eef921c4e1 Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Wed, 29 Oct 2025 08:50:42 +0000 Subject: [PATCH] Optimize BlockManifest.describe_outputs The optimization introduces **pre-computed constant caching** by moving the `OutputDefinition` object creation to module load time as `_CACHED_OUTPUTS`, rather than constructing it fresh on every method call. **Key changes:** - Added module-level constant `_CACHED_OUTPUTS = [OutputDefinition(name="image", kind=[IMAGE_KIND])]` - Modified `describe_outputs()` to return the cached list instead of creating new objects **Why this creates a speedup:** 1. **Eliminates object construction overhead**: Instead of creating new `OutputDefinition` objects and list wrappers on every call, the method simply returns a pre-existing reference 2. **Reduces function call stack depth**: No constructor calls or list comprehension execution during runtime 3. **Memory allocation savings**: Avoids repeated heap allocations for identical objects **Performance characteristics based on test results:** - **Repeated calls benefit most**: The `test_describe_outputs_performance_under_multiple_calls` shows 549% speedup when called 1000 times, demonstrating excellent scaling for high-frequency usage - **Single calls see dramatic improvement**: Individual calls show 1300-1400% speedups, indicating the object creation overhead was substantial - **Consistent across all access patterns**: Whether called once or multiple times, the optimization provides significant benefits This optimization is particularly effective for workflow blocks that may be queried frequently for their output definitions during pipeline construction or validation phases. --- .../models/foundation/stability_ai/outpainting/v1.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inference/core/workflows/core_steps/models/foundation/stability_ai/outpainting/v1.py b/inference/core/workflows/core_steps/models/foundation/stability_ai/outpainting/v1.py index 5358d1c019..d263425771 100644 --- a/inference/core/workflows/core_steps/models/foundation/stability_ai/outpainting/v1.py +++ b/inference/core/workflows/core_steps/models/foundation/stability_ai/outpainting/v1.py @@ -30,6 +30,8 @@ WorkflowBlockManifest, ) +_CACHED_OUTPUTS = [OutputDefinition(name="image", kind=[IMAGE_KIND])] + LONG_DESCRIPTION = """ The block wraps [Stability AI outpainting API](https://platform.stability.ai/docs/api-reference#tag/Edit/paths/~1v2beta~1stable-image~1edit~1outpaint/post) and @@ -182,9 +184,7 @@ class BlockManifest(WorkflowBlockManifest): @classmethod def describe_outputs(cls) -> List[OutputDefinition]: - return [ - OutputDefinition(name="image", kind=[IMAGE_KIND]), - ] + return _CACHED_OUTPUTS @classmethod def get_execution_engine_compatibility(cls) -> Optional[str]: