⚡️ Speed up method VertexAITextEmbeddingConfig.get_mapped_special_auth_params by 33%
#124
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.
📄 33% (0.33x) speedup for
VertexAITextEmbeddingConfig.get_mapped_special_auth_paramsinlitellm/llms/vertex_ai/vertex_embeddings/transformation.py⏱️ Runtime :
573 microseconds→429 microseconds(best of147runs)📝 Explanation and details
The optimization replaces dictionary creation on every method call with a pre-allocated module-level constant. Instead of creating a new dictionary
{"project": "vertex_project", "region_name": "vertex_location"}each timeget_mapped_special_auth_params()is called, the optimized version defines_MAPPED_SPECIAL_AUTH_PARAMSas a constant and returns it directly.This eliminates the overhead of:
The line profiler shows the per-call time dropping from 327.4ns to 235.1ns (28% improvement per call), which compounds significantly under load. Test results demonstrate consistent 25-47% speedup across all scenarios, with the optimization being particularly effective for:
This is a classic constant hoisting optimization that's especially valuable for methods that return static data and are called frequently in production systems.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-VertexAITextEmbeddingConfig.get_mapped_special_auth_params-mhc6bz0pand push.