⚡️ Speed up method RecraftImageGenerationConfig.map_openai_params by 25%
          #154
        
          
      
  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.
  
    
  
    
📄 25% (0.25x) speedup for
RecraftImageGenerationConfig.map_openai_paramsinlitellm/llms/recraft/image_generation/transformation.py⏱️ Runtime :
320 microseconds→256 microseconds(best of21runs)📝 Explanation and details
The optimized code achieves a 24% speedup through two key optimizations:
1. Converting
supported_paramsto a set for faster membership testingsupported_params = self.get_supported_openai_params(model)tosupported_params = set(self.get_supported_openai_params(model))k in supported_params) is O(1) vs O(n) for lists, providing significant speedup when checking many parameters2. Caching
optional_params.keys()to avoid repeated method callsoptional_param_keys = optional_params.keys()and used it in the comparison.keys()method repeatedly in the hot loop3. Minor optimization: using
continueinstead ofpasspasswithcontinuein the drop_params branchcontinueis slightly more efficient as it directly jumps to the next iterationPerformance gains are most significant for large-scale scenarios:
test_large_number_of_unsupported_params: 33.0μs → 22.3μs)The optimizations are particularly effective when
drop_params=Trueand there are many unsupported parameters to filter, as the O(1) set lookups compound the performance benefits.✅ Correctness verification report:
⚙️ Existing Unit Tests and Runtime
test_litellm/llms/recraft/image_generation/test_recraft_image_gen_transformation.py::TestRecraftImageGenerationTransformation.test_map_openai_params_supported_paramstest_litellm/llms/recraft/image_generation/test_recraft_image_gen_transformation.py::TestRecraftImageGenerationTransformation.test_map_openai_params_unsupported_param_drop_falsetest_litellm/llms/recraft/image_generation/test_recraft_image_gen_transformation.py::TestRecraftImageGenerationTransformation.test_map_openai_params_unsupported_param_drop_true🌀 Generated Regression Tests and Runtime
🔎 Concolic Coverage Tests and Runtime
codeflash_concolic_kt42dg31/tmphn1emm9w/test_concolic_coverage.py::test_RecraftImageGenerationConfig_map_openai_paramscodeflash_concolic_kt42dg31/tmphn1emm9w/test_concolic_coverage.py::test_RecraftImageGenerationConfig_map_openai_params_2codeflash_concolic_kt42dg31/tmphn1emm9w/test_concolic_coverage.py::test_RecraftImageGenerationConfig_map_openai_params_3To edit these changes
git checkout codeflash/optimize-RecraftImageGenerationConfig.map_openai_params-mhdc6hd4and push.