⚡️ Speed up method _NamedVectors.text2vec_ollama by 5%
#89
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.
📄 5% (0.05x) speedup for
_NamedVectors.text2vec_ollamainweaviate/collections/classes/config_named_vectors.py⏱️ Runtime :
2.77 milliseconds→2.63 milliseconds(best of33runs)📝 Explanation and details
The optimization achieves a 5% speedup through local variable aliasing that reduces global namespace lookups during object instantiation.
Key changes:
_Text2VecOllamaConfigand_NamedVectorConfigCreateto local variables (VecConfigandNamedVecConfigCreate) at function startWhy this is faster:
In Python, global namespace lookups (like
_Text2VecOllamaConfig) are slower than local variable access. By creating local references to these classes, each constructor call avoids repeated global lookups. This is particularly beneficial because:Test case performance patterns:
The optimization shows consistent 4-11% improvements across all test scenarios, with particularly strong gains in:
The uniform improvement across diverse inputs confirms this is a fundamental performance enhancement rather than scenario-specific optimization.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
⏪ Replay Tests and Runtime
test_pytest_testcollectiontest_batch_py_testcollectiontest_classes_generative_py_testcollectiontest_confi__replay_test_0.py::test_weaviate_collections_classes_config_named_vectors__NamedVectors_text2vec_ollamaTo edit these changes
git checkout codeflash/optimize-_NamedVectors.text2vec_ollama-mh2wen3oand push.