⚡️ Speed up function _custom_logger_class_exists_in_success_callbacks by 87%
          #164
        
          
      
  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.
  
    
  
    
📄 87% (0.87x) speedup for
_custom_logger_class_exists_in_success_callbacksinlitellm/utils.py⏱️ Runtime :
295 microseconds→158 microseconds(best of33runs)📝 Explanation and details
The optimization eliminates the expensive list concatenation operation (
litellm.success_callback + litellm._async_success_callback) that was creating a temporary combined list on every function call. This concatenation dominated the runtime, consuming 97.9% of execution time according to the line profiler.Key optimizations:
cb_type = type(callback_class)to avoid repeatedtype()calls duringisinstance()checksPerformance benefits:
The optimization is particularly effective for scenarios with:
success_callback) since it's checked first✅ Correctness verification report:
⚙️ Existing Unit Tests and Runtime
litellm_utils_tests/test_utils.py::test_custom_logger_exists_in_callbacks_individual_functions🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-_custom_logger_class_exists_in_success_callbacks-mhditqlzand push.