⚡️ Speed up method ModelProviderCredentialRequest.validate_provider by 32% in PR #10351 (model-provider-keys-v2)#10441
Conversation
🔧 (variable/model.py): add category field to VariableBase and VariableRead models 🔧 (variable/model.py): add validation for category field in VariableBase and VariableUpdate models 🔧 (variable/constants.py): define valid categories and add new categories 🔧 (variable/service.py): update category in db_variable if variable has a category and encrypt value if type is CREDENTIAL_TYPE
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Edwin Jose <edwin.jose@datastax.com> Co-authored-by: Cristhian Zanforlin Lousa <cristhian.lousa@gmail.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: Lucas Oliveira <62335616+lucaseduoli@users.noreply.github.com> Co-authored-by: Rodrigo Nader <rodrigosilvanader@gmail.com> Co-authored-by: Deon Sanchez <69873175+deon-sanchez@users.noreply.github.com> Co-authored-by: April I. Murphy <36110273+aimurphy@users.noreply.github.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com> Co-authored-by: Yuqi Tang <yuqi.tang@datastax.com> fix: store mcp sse headers and use them on connection (#9148) fix: prevent unintentional sidebar text selection (#8895) fix: Exclude base path from custom component loading (#9098) fix.py): remove unnecessary test case for GitHub issue #8967 and fix test_component_merging_logic method to handle custom component loading failure properly
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
…lobal variables ✨ (use-get-categories.ts): introduce use-get-categories query function to fetch category variables ✨ (use-post-global-variables.ts): add category parameter to post global variables function 📝 (global_variables/index.ts): update GlobalVariable type to include category field
…PatchGlobalVariablesParams interface
- Introduced a new Model Providers page with components for displaying enabled and available providers. - Updated the settings sidebar to include a link to the Model Providers page. - Added a custom CSS class for improved text styling.
- Introduced ModelInputComponent for selecting models with enhanced search and filtering capabilities. - Updated ParameterRenderComponent to handle model_type and related properties. - Refactored dropdownComponent to improve code organization and readability. - Added new types for model configuration in the API definitions.
- Removed unused placeholder formatting in Dropdown component. - Simplified ModelInputComponent by cleaning up imports and restructuring state management. - Introduced API key input functionality for model selection. - Enhanced rendering logic for model options and search input. - Improved code organization and readability across components.
…ategory - Refactored ModelInputComponent to replace search_category with providers for better clarity and functionality. - Updated related types and props to accommodate the new providers structure. - Enhanced the handling of model selection to include additional metadata for selected models. - Adjusted ParameterRenderComponent to reflect changes in props passed to child components.
…PI key handling - Made the model_selection input required and added a placeholder for better user guidance. - Refactored the model selection logic to handle selected models more effectively, including additional metadata. - Updated the rendering of model options to improve clarity and user experience. - Implemented a search feature for model selection, allowing users to filter options dynamically. - Enhanced API key input handling to streamline the process of entering and managing API keys for selected models.
- Added ApiKeyModal component to facilitate API key entry and management for models. - Integrated modal into ModelInputComponent, allowing users to input and save API keys. - Refactored input handling and state management for improved user experience. - Cleaned up imports and organized component structure for better maintainability.
…component - Introduced new constants for model providers in the API helper. - Implemented useGetModelProviders hook to fetch and manage model provider data. - Updated Providers component to utilize the new hook, replacing mock data with dynamic provider information. - Enhanced UI to display model provider status and count, improving user interaction and experience.
…odel-provider-keys-v2
The optimization achieves a **31% speedup** through two key changes: 1. **Module-level caching**: Moves the expensive `get_model_provider_metadata().keys()` call from inside the validator to module load time, storing it in `_VALID_PROVIDERS`. This eliminates repeated calls to what appears to be a costly metadata retrieval function every time validation occurs. 2. **Set-based membership testing**: Converts the provider keys to a `set` instead of using a `list`, changing the membership test from O(n) to O(1) complexity. This is particularly beneficial when there are many supported providers. The optimization is most effective for scenarios with: - **Repeated validations**: Multiple provider validations benefit from the one-time metadata fetch - **Large provider lists**: The set lookup becomes increasingly advantageous as the number of supported providers grows (as shown in the `test_large_number_of_providers_invalid` test case) - **High-frequency validation paths**: Any code path that validates providers multiple times sees cumulative benefits The cached approach trades a small amount of memory for significant runtime improvement, while maintaining identical validation behavior and error messages.
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Comment |
Codecov Report❌ Patch coverage is ❌ Your patch status has failed because the patch coverage (32.82%) is below the target coverage (40.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## model-provider-keys-v2 #10441 +/- ##
=========================================================
Coverage ? 30.21%
=========================================================
Files ? 1329
Lines ? 60310
Branches ? 9021
=========================================================
Hits ? 18221
Misses ? 41258
Partials ? 831
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
716d4b3 to
bd3f04e
Compare
|
⚡️ This pull request contains optimizations for PR #10351
If you approve this dependent PR, these changes will be merged into the original PR branch
model-provider-keys-v2.📄 32% (0.32x) speedup for
ModelProviderCredentialRequest.validate_providerinsrc/backend/base/langflow/api/v1/model_provider_credentials.py⏱️ Runtime :
20.8 microseconds→15.8 microseconds(best of37runs)📝 Explanation and details
The optimization achieves a 31% speedup through two key changes:
Module-level caching: Moves the expensive
get_model_provider_metadata().keys()call from inside the validator to module load time, storing it in_VALID_PROVIDERS. This eliminates repeated calls to what appears to be a costly metadata retrieval function every time validation occurs.Set-based membership testing: Converts the provider keys to a
setinstead of using alist, changing the membership test from O(n) to O(1) complexity. This is particularly beneficial when there are many supported providers.The optimization is most effective for scenarios with:
test_large_number_of_providers_invalidtest case)The cached approach trades a small amount of memory for significant runtime improvement, while maintaining identical validation behavior and error messages.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-pr10351-2025-10-29T15.27.18and push.