⚡️ Speed up method AmazonMistralConfig.get_config by 23%
#172
+18
−15
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.
📄 23% (0.23x) speedup for
AmazonMistralConfig.get_configinlitellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py⏱️ Runtime :
2.23 milliseconds→1.81 milliseconds(best of481runs)📝 Explanation and details
The optimization achieves a 23% speedup through two key changes:
1. Eliminated expensive
locals()usage in__init__:locals_.copy()and dictionary iteration with a direct tuple of parameter names and values(("max_tokens", max_tokens), ...)is much more efficient than dictionary operations2. Optimized type checking in
get_config:isinstance(v, excluded_types)totype(v) not in excluded_typesFunctionType),type()is significantly faster thanisinstance()since it doesn't need to check inheritance chainsPerformance characteristics:
get_configis called frequently (shown in test cases with 500+ calls achieving 20%+ speedup)The changes preserve exact behavioral compatibility while eliminating unnecessary computational overhead in both initialization and configuration retrieval.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-AmazonMistralConfig.get_config-mhdnam9zand push.