⚡️ Speed up function available_models by 104% - #4
Open
codeflash-ai[bot] wants to merge 1 commit into
Open
Conversation
**Optimization rationale:** - Creating a list from `_MODELS.keys()` is an O(N) operation and was repeated on every function call. - By caching the result at module load in `_MODEL_NAMES` and returning a copy in each call, we significantly reduce runtime for repeated calls, while still preserving the immutability guarantee for the API user. - All comments are preserved; only a new explanatory comment is added for the new variable. - The return value remains exactly the same (a fresh `list` same as before).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📄 104% (1.04x) speedup for
available_modelsinwhisper/__init__.py⏱️ Runtime :
13.3 microseconds→6.53 microseconds(best of993runs)📝 Explanation and details
Optimization rationale:
_MODELS.keys()is an O(N) operation and was repeated on every function call._MODEL_NAMESand returning a copy in each call, we significantly reduce runtime for repeated calls, while still preserving the immutability guarantee for the API user.listsame as before).✅ Correctness verification report:
🌀 Generated Regression Tests Details
To edit these changes
git checkout codeflash/optimize-available_models-mayscm19and push.