Skip to content

⚡️ Speed up function _build_model_config by 38% in PR #11807 (EJ/multi-api-support-merge-conflicts)#11808

Closed
codeflash-ai[bot] wants to merge 38 commits into
mainfrom
codeflash/optimize-pr11807-2026-02-18T17.19.30
Closed

⚡️ Speed up function _build_model_config by 38% in PR #11807 (EJ/multi-api-support-merge-conflicts)#11808
codeflash-ai[bot] wants to merge 38 commits into
mainfrom
codeflash/optimize-pr11807-2026-02-18T17.19.30

Conversation

@codeflash-ai
Copy link
Copy Markdown
Contributor

@codeflash-ai codeflash-ai Bot commented Feb 18, 2026

⚡️ This pull request contains optimizations for PR #11807

If you approve this dependent PR, these changes will be merged into the original PR branch EJ/multi-api-support-merge-conflicts.

This PR will be automatically closed if the original PR is merged.


📄 38% (0.38x) speedup for _build_model_config in src/backend/base/langflow/agentic/flows/langflow_assistant.py

⏱️ Runtime : 2.59 milliseconds 1.88 milliseconds (best of 74 runs)

📝 Explanation and details

The optimized code achieves a 37% speedup by eliminating repeated allocations of the same constant data structures on every function call.

Key Optimizations

1. Module-level constant extraction
The original code reconstructs the model_classes dictionary with 5 key-value pairs on every invocation. By moving this to module-level, the dictionary is allocated once at import time rather than 4,796+ times during execution. The line profiler shows the original spent ~11.8ms just building this dictionary across all calls (lines showing 1.7-2.7ms each for the dict construction).

2. Metadata template with shallow copy
Instead of constructing the metadata dictionary inline with 4 key-value pairs each time, the optimized version maintains a _metadata_template at module-level and performs a shallow .copy() operation. Dictionary copying in Python is highly optimized in C and faster than creating a new dict from scratch with multiple key assignments. The copy operation takes ~2.47ms total versus the original's inline construction which consumed more time across multiple lines.

3. Why this works in Python
Python dictionaries have allocation overhead - each {} literal triggers memory allocation, hash table setup, and key insertion operations. By reusing pre-allocated structures, we avoid this overhead. The shallow copy is efficient because it only copies references to the string keys/values, not the strings themselves.

Test Case Performance

The optimization excels across all test scenarios:

  • Known providers: Fast lookups from module-level dict (most common case)
  • Unknown providers: Same performance as original for the default fallback
  • Large-scale tests: The benefits compound - the 1000-iteration tests see cumulative savings from avoiding 1000+ dict constructions
  • Edge cases: Empty strings, special characters, long names all benefit equally since the optimization is in constant allocation, not string handling

Impact Assessment

Without function_references, we cannot determine call frequency in production, but this is a pure win optimization - it maintains identical behavior (same output structure, key ordering, and semantics) while being strictly faster. Any code path calling this function repeatedly (e.g., batch model configuration, API request handling loops) will see proportional improvements.

Correctness verification report:

Test Status
⚙️ Existing Unit Tests 20 Passed
🌀 Generated Regression Tests 4789 Passed
⏪ Replay Tests 🔘 None Found
🔎 Concolic Coverage Tests 🔘 None Found
📊 Tests Coverage 100.0%
⚙️ Click to see Existing Unit Tests
🌀 Click to see Generated Regression Tests
import pytest  # used for our unit tests
from langflow.agentic.flows.langflow_assistant import _build_model_config


def test_returns_list_of_single_dict_for_known_provider_openai():
    # Call the function with a known provider and a typical model name
    provider = "OpenAI"
    model_name = "gpt-4o"
    codeflash_output = _build_model_config(provider, model_name); result = codeflash_output

    # The single element should be a dictionary with the expected top-level keys
    cfg = result[0]


@pytest.mark.parametrize(
    "provider, expected_model_class",
    [
        ("Anthropic", "ChatAnthropic"),
        ("Google Generative AI", "ChatGoogleGenerativeAI"),
        ("Groq", "ChatGroq"),
        ("Azure OpenAI", "AzureChatOpenAI"),
    ],
)
def test_model_class_mapping_for_known_providers(provider, expected_model_class):
    # Ensure each listed provider maps to the correct model_class string
    cfg = _build_model_config(provider, "any-model")[0]


def test_unknown_provider_uses_default_model_class():
    # If provider is not present in the internal mapping, default should be ChatAnthropic
    provider = "Some Unknown Provider"
    cfg = _build_model_config(provider, "mymodel")[0]


def test_empty_strings_for_provider_and_model_name():
    # Empty strings are allowed; provider empty -> default model_class
    cfg = _build_model_config("", "")[0]


def test_none_provider_and_none_model_name():
    # Passing None (despite annotation expecting str) should still produce a result,
    # using the default model_class because None is not a mapped provider key.
    cfg = _build_model_config(None, None)[0]


def test_special_characters_and_whitespace():
    # Providers and model names with special ASCII characters and whitespace should be preserved
    provider = "Custom-Provider! @#$"
    model_name = " model with spaces\tand\t tabs "
    cfg = _build_model_config(provider, model_name)[0]


def test_returned_objects_are_new_each_call():
    # Ensure that each call returns fresh dict/list objects (no accidental reuse)
    a = _build_model_config("OpenAI", "a")[0]
    b = _build_model_config("OpenAI", "b")[0]
    # Modifying one should not affect the other
    a["name"] = "mutated"


def test_large_scale_many_calls_consistency():
    # Call the function 1000 times with a variety of provider names (known and unknown)
    providers = ["OpenAI", "Anthropic", "Google Generative AI", "Groq", "Azure OpenAI", "", "CustomX"]
    # Prepare counters to verify distribution and consistency
    results = []
    for i in range(1000):
        prov = providers[i % len(providers)]
        model_name = f"model-{i}"
        codeflash_output = _build_model_config(prov, model_name); cfg = codeflash_output
        item = cfg[0]
        results.append(item["metadata"]["model_class"])


def test_large_model_name_lengths_and_repeated_calls():
    # Test with very long model names to ensure no truncation or errors
    long_name = "m" * 5000  # 5000 characters long
    # Call multiple times to ensure stability across repeated invocations
    for _ in range(100):
        cfg = _build_model_config("OpenAI", long_name)[0]
# codeflash_output is used to check that the output of the original code is the same as that of the optimized code.
#------------------------------------------------
import pytest
from langflow.agentic.flows.langflow_assistant import _build_model_config


class TestBuildModelConfigBasic:
    """Basic tests for _build_model_config with normal usage patterns."""

    def test_openai_provider_returns_correct_structure(self):
        """Test that OpenAI provider returns correctly formatted config."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result = codeflash_output
        
        # Verify the single config dict has all required keys
        config = result[0]

    def test_openai_provider_sets_correct_model_class(self):
        """Test that OpenAI provider maps to ChatOpenAI model class."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result = codeflash_output
        config = result[0]

    def test_anthropic_provider_returns_correct_structure(self):
        """Test that Anthropic provider returns correctly formatted config."""
        codeflash_output = _build_model_config("Anthropic", "claude-3-opus"); result = codeflash_output
        
        config = result[0]

    def test_anthropic_provider_sets_correct_model_class(self):
        """Test that Anthropic provider maps to ChatAnthropic model class."""
        codeflash_output = _build_model_config("Anthropic", "claude-3-opus"); result = codeflash_output
        config = result[0]

    def test_google_provider_returns_correct_model_class(self):
        """Test that Google Generative AI provider maps correctly."""
        codeflash_output = _build_model_config("Google Generative AI", "gemini-pro"); result = codeflash_output
        config = result[0]

    def test_groq_provider_returns_correct_model_class(self):
        """Test that Groq provider maps to ChatGroq model class."""
        codeflash_output = _build_model_config("Groq", "mixtral-8x7b"); result = codeflash_output
        config = result[0]

    def test_azure_openai_provider_returns_correct_model_class(self):
        """Test that Azure OpenAI provider maps to AzureChatOpenAI model class."""
        codeflash_output = _build_model_config("Azure OpenAI", "gpt-4-deployment"); result = codeflash_output
        config = result[0]

    def test_metadata_contains_api_key_param(self):
        """Test that metadata always contains api_key_param field."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result = codeflash_output
        metadata = result[0]["metadata"]

    def test_metadata_contains_model_name_param(self):
        """Test that metadata always contains model_name_param field."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result = codeflash_output
        metadata = result[0]["metadata"]

    def test_metadata_contains_context_length(self):
        """Test that metadata always contains context_length field."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result = codeflash_output
        metadata = result[0]["metadata"]

    def test_icon_field_matches_provider(self):
        """Test that icon field is set to the provider name."""
        codeflash_output = _build_model_config("Anthropic", "claude-3"); result = codeflash_output
        config = result[0]

    def test_name_field_matches_model_name(self):
        """Test that name field is set to the provided model_name."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4-turbo"); result = codeflash_output
        config = result[0]

    def test_provider_field_matches_input_provider(self):
        """Test that provider field matches the input provider parameter."""
        codeflash_output = _build_model_config("Groq", "mixtral"); result = codeflash_output
        config = result[0]


class TestBuildModelConfigEdgeCases:
    """Edge case tests for _build_model_config."""

    def test_unknown_provider_defaults_to_chat_anthropic(self):
        """Test that unknown provider defaults to ChatAnthropic model class."""
        codeflash_output = _build_model_config("UnknownProvider", "some-model"); result = codeflash_output
        config = result[0]

    def test_empty_string_provider_defaults_to_chat_anthropic(self):
        """Test that empty string provider defaults to ChatAnthropic."""
        codeflash_output = _build_model_config("", "model-name"); result = codeflash_output
        config = result[0]

    def test_empty_string_model_name(self):
        """Test that empty string model_name is accepted."""
        codeflash_output = _build_model_config("OpenAI", ""); result = codeflash_output
        config = result[0]

    def test_whitespace_only_provider(self):
        """Test that whitespace-only provider string is treated as unknown."""
        codeflash_output = _build_model_config("   ", "gpt-4"); result = codeflash_output
        config = result[0]

    def test_whitespace_only_model_name(self):
        """Test that whitespace-only model_name is preserved."""
        codeflash_output = _build_model_config("OpenAI", "   "); result = codeflash_output
        config = result[0]

    def test_case_sensitive_provider_matching(self):
        """Test that provider matching is case-sensitive."""
        codeflash_output = _build_model_config("openai", "gpt-4"); result = codeflash_output
        config = result[0]

    def test_provider_with_extra_spaces(self):
        """Test that provider with leading/trailing spaces doesn't match."""
        codeflash_output = _build_model_config(" OpenAI ", "gpt-4"); result = codeflash_output
        config = result[0]

    def test_special_characters_in_model_name(self):
        """Test that special characters in model_name are preserved."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4-turbo-2024-04-09"); result = codeflash_output
        config = result[0]

    def test_special_characters_in_provider(self):
        """Test that special characters in provider string are preserved."""
        codeflash_output = _build_model_config("Provider@#$", "model"); result = codeflash_output
        config = result[0]

    def test_very_long_model_name(self):
        """Test that very long model_name strings are handled."""
        long_name = "a" * 1000
        codeflash_output = _build_model_config("OpenAI", long_name); result = codeflash_output
        config = result[0]

    def test_very_long_provider_string(self):
        """Test that very long provider strings are handled."""
        long_provider = "b" * 500
        codeflash_output = _build_model_config(long_provider, "model"); result = codeflash_output
        config = result[0]

    def test_unicode_characters_in_model_name(self):
        """Test that unicode characters in model_name are preserved."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4-日本語"); result = codeflash_output
        config = result[0]

    def test_unicode_characters_in_provider(self):
        """Test that unicode characters in provider are preserved."""
        codeflash_output = _build_model_config("OpenAI-中文", "model"); result = codeflash_output
        config = result[0]

    def test_newline_in_model_name(self):
        """Test that newline characters in model_name are preserved."""
        codeflash_output = _build_model_config("OpenAI", "gpt\n4"); result = codeflash_output
        config = result[0]

    def test_tab_characters_in_model_name(self):
        """Test that tab characters in model_name are preserved."""
        codeflash_output = _build_model_config("OpenAI", "gpt\t4"); result = codeflash_output
        config = result[0]

    def test_single_character_provider(self):
        """Test with single character provider."""
        codeflash_output = _build_model_config("X", "model"); result = codeflash_output
        config = result[0]

    def test_single_character_model_name(self):
        """Test with single character model_name."""
        codeflash_output = _build_model_config("OpenAI", "M"); result = codeflash_output
        config = result[0]

    def test_numeric_string_provider(self):
        """Test with numeric string as provider."""
        codeflash_output = _build_model_config("12345", "model"); result = codeflash_output
        config = result[0]

    def test_numeric_string_model_name(self):
        """Test with numeric string as model_name."""
        codeflash_output = _build_model_config("OpenAI", "4.0"); result = codeflash_output
        config = result[0]

    def test_hyphenated_provider_not_matching(self):
        """Test that hyphenated variations don't match known providers."""
        codeflash_output = _build_model_config("Azure-OpenAI", "model"); result = codeflash_output
        config = result[0]

    def test_context_length_is_always_same(self):
        """Test that context_length is always 128000 regardless of provider."""
        providers = ["OpenAI", "Anthropic", "Google Generative AI", "Groq", "Azure OpenAI", "Unknown"]
        
        for provider in providers:
            codeflash_output = _build_model_config(provider, "model"); result = codeflash_output
            config = result[0]


class TestBuildModelConfigReturnType:
    """Tests for return type and structure verification."""

    def test_return_type_is_list(self):
        """Test that function returns a list."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result = codeflash_output

    def test_return_list_contains_exactly_one_dict(self):
        """Test that return list contains exactly one dictionary."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result = codeflash_output

    def test_config_dict_has_exactly_four_top_level_keys(self):
        """Test that config dict has exactly four top-level keys."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result = codeflash_output
        config = result[0]
        
        keys = {"icon", "metadata", "name", "provider"}

    def test_metadata_dict_has_exactly_four_keys(self):
        """Test that metadata dict has exactly four keys."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result = codeflash_output
        metadata = result[0]["metadata"]
        
        keys = {"api_key_param", "context_length", "model_class", "model_name_param"}

    def test_all_values_are_strings_or_integers(self):
        """Test that all config values are strings or integers."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result = codeflash_output
        config = result[0]
        
        # Metadata values
        metadata = config["metadata"]

    def test_context_length_is_integer(self):
        """Test that context_length is specifically an integer."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result = codeflash_output
        context_length = result[0]["metadata"]["context_length"]

    def test_model_class_is_string(self):
        """Test that model_class is a string."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result = codeflash_output
        model_class = result[0]["metadata"]["model_class"]


class TestBuildModelConfigConsistency:
    """Tests to verify consistent behavior across multiple calls."""

    def test_multiple_calls_same_input_return_same_output(self):
        """Test that multiple calls with same input return identical output."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result1 = codeflash_output
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result2 = codeflash_output

    def test_all_known_providers_have_correct_mapping(self):
        """Test all known providers map to their correct model classes."""
        expected_mappings = {
            "OpenAI": "ChatOpenAI",
            "Anthropic": "ChatAnthropic",
            "Google Generative AI": "ChatGoogleGenerativeAI",
            "Groq": "ChatGroq",
            "Azure OpenAI": "AzureChatOpenAI",
        }
        
        for provider, expected_class in expected_mappings.items():
            codeflash_output = _build_model_config(provider, "test-model"); result = codeflash_output
            config = result[0]

    def test_different_model_names_produce_different_configs(self):
        """Test that different model names produce different name fields."""
        codeflash_output = _build_model_config("OpenAI", "gpt-4"); result1 = codeflash_output
        codeflash_output = _build_model_config("OpenAI", "gpt-3.5-turbo"); result2 = codeflash_output

    def test_different_providers_produce_different_model_classes(self):
        """Test that different providers produce different model classes."""
        codeflash_output = _build_model_config("OpenAI", "model"); result_openai = codeflash_output
        codeflash_output = _build_model_config("Anthropic", "model"); result_anthropic = codeflash_output

    def test_api_key_param_always_api_key(self):
        """Test that api_key_param is always 'api_key' for all providers."""
        providers = ["OpenAI", "Anthropic", "Google Generative AI", "Groq", "Azure OpenAI", "Unknown"]
        
        for provider in providers:
            codeflash_output = _build_model_config(provider, "model"); result = codeflash_output
            config = result[0]

    def test_model_name_param_always_model(self):
        """Test that model_name_param is always 'model' for all providers."""
        providers = ["OpenAI", "Anthropic", "Google Generative AI", "Groq", "Azure OpenAI", "Unknown"]
        
        for provider in providers:
            codeflash_output = _build_model_config(provider, "model"); result = codeflash_output
            config = result[0]


class TestBuildModelConfigLargeScale:
    """Large-scale and performance-related tests."""

    def test_many_calls_with_different_model_names(self):
        """Test function with 1000 different model names."""
        for i in range(1000):
            model_name = f"model-{i}"
            codeflash_output = _build_model_config("OpenAI", model_name); result = codeflash_output
            config = result[0]

    def test_many_calls_with_different_providers(self):
        """Test function with 1000 different provider strings."""
        for i in range(1000):
            provider = f"Provider-{i}"
            codeflash_output = _build_model_config(provider, "model"); result = codeflash_output
            config = result[0]

    def test_very_large_model_name(self):
        """Test with extremely large model_name string (10000 chars)."""
        large_name = "x" * 10000
        codeflash_output = _build_model_config("OpenAI", large_name); result = codeflash_output
        config = result[0]

    def test_very_large_provider_string(self):
        """Test with extremely large provider string (5000 chars)."""
        large_provider = "y" * 5000
        codeflash_output = _build_model_config(large_provider, "model"); result = codeflash_output
        config = result[0]

    def test_repeated_calls_maintain_consistency(self):
        """Test that 100 repeated calls with same input maintain consistency."""
        codeflash_output = _build_model_config("Anthropic", "claude-3"); expected_result = codeflash_output
        
        for _ in range(100):
            codeflash_output = _build_model_config("Anthropic", "claude-3"); result = codeflash_output

    def test_all_known_providers_in_sequence(self):
        """Test calling function with all known providers in sequence."""
        providers = ["OpenAI", "Anthropic", "Google Generative AI", "Groq", "Azure OpenAI"]
        
        results = []
        for provider in providers:
            codeflash_output = _build_model_config(provider, "test-model"); result = codeflash_output
            results.append(result)
        
        # Verify all results are valid
        for result in results:
            pass

    def test_combined_long_provider_and_model_names(self):
        """Test with both provider and model_name being very long."""
        long_provider = "Provider" * 100  # 800 chars
        long_model = "Model" * 100  # 500 chars
        
        codeflash_output = _build_model_config(long_provider, long_model); result = codeflash_output
        config = result[0]

    def test_stress_test_with_special_chars_in_loop(self):
        """Stress test with special characters in 500 iterations."""
        special_chars = "!@#$%^&*()_+-=[]{}|;:',.<>?/"
        
        for i in range(500):
            char = special_chars[i % len(special_chars)]
            provider = f"Provider{char}"
            model_name = f"Model{char}"
            
            codeflash_output = _build_model_config(provider, model_name); result = codeflash_output
            config = result[0]

    def test_rapid_sequential_calls_with_known_providers(self):
        """Rapidly call function with known providers 200 times each."""
        known_providers = ["OpenAI", "Anthropic", "Google Generative AI", "Groq", "Azure OpenAI"]
        
        for _ in range(200):
            for provider in known_providers:
                codeflash_output = _build_model_config(provider, "model"); result = codeflash_output
                config = result[0]
# codeflash_output is used to check that the output of the original code is the same as that of the optimized code.

To edit these changes git checkout codeflash/optimize-pr11807-2026-02-18T17.19.30 and push.

Codeflash

edwinjosechittilappilly and others added 30 commits January 26, 2026 10:49
Enhances provider variable handling by introducing a metadata structure for all required variables per provider, including support for providers with multiple required variables (e.g., IBM WatsonX). Updates backend API to return full variable info, adapts frontend to dynamically render and save multiple variables, and adds comprehensive tests for the new API response. Also updates static mappings and introduces a new React hook for fetching provider variable metadata.
Replaces per-variable auto-save with a batch save for all provider variables, improving UX and reducing API calls. Updates input handling to show masked values for secrets, disables save button until all required fields are filled, and provides clearer feedback for configured variables.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Centralize MODEL_PROVIDER_METADATA in model_metadata.py and update unified_models.py to import and use it. Refactor provider validation to accept all required variables as a dictionary, supporting providers with multiple required credentials. Simplify and generalize validation logic for all providers.
Centralizes provider-specific parameter mappings in model_metadata.py and introduces get_provider_param_mapping for reuse. Updates unified_models.py to use this mapping, reducing duplication and improving maintainability for model class, API key, and other provider-specific parameters.
Replaces the API key-specific check with a more general configuration requirement, considering all required provider variables (not just secrets). Updates related UI logic and labels to reflect this broader configuration requirement.
Update logic to consider both secret and non-secret variables when determining enabled providers. Refactor to fetch all required provider variables, not just credentials, and ensure correct values are passed for validation. This improves accuracy for providers that require non-secret configuration variables.
Replaces provider-specific field toggling logic in starter project LanguageModelComponent definitions with a call to apply_provider_variable_config_to_build_config. This centralizes provider-specific configuration, improving maintainability and extensibility for new model providers.
autofix-ci Bot and others added 7 commits February 2, 2026 19:13
Improve provider enablement checks and simplify model options handling.

- Exclude the /models router from OpenAPI schema (include_in_schema=False).
- Treat providers as enabled when credential variables exist (check non-empty values and strip whitespace) and avoid per-read API validation to reduce external latency; add skip_validation flag (default True) to _validate_and_get_enabled_providers to control validation behavior.
- Consolidate credential collection logic (use env fallback, decrypt values when present) and downgrade parse/validation log noise by using debug level and safer JSON parsing.
- Harden variable parsing in API endpoints: check for empty/None values, strip whitespace before JSON parsing, and handle parsing failures gracefully.
- Add json import where needed and remove redundant local imports.
- Always set build_config model input_types based on embedding vs language model types (ensures connection handles are enabled appropriately) and remove previous visibility-only logic.

These changes aim to be more robust against empty/whitespace variable values, reduce unnecessary external validation calls, and simplify configuration logic.
The optimized code achieves a **37% speedup** by eliminating repeated allocations of the same constant data structures on every function call.

## Key Optimizations

**1. Module-level constant extraction**
The original code reconstructs the `model_classes` dictionary with 5 key-value pairs on every invocation. By moving this to module-level, the dictionary is allocated once at import time rather than 4,796+ times during execution. The line profiler shows the original spent ~11.8ms just building this dictionary across all calls (lines showing 1.7-2.7ms each for the dict construction).

**2. Metadata template with shallow copy**
Instead of constructing the metadata dictionary inline with 4 key-value pairs each time, the optimized version maintains a `_metadata_template` at module-level and performs a shallow `.copy()` operation. Dictionary copying in Python is highly optimized in C and faster than creating a new dict from scratch with multiple key assignments. The copy operation takes ~2.47ms total versus the original's inline construction which consumed more time across multiple lines.

**3. Why this works in Python**
Python dictionaries have allocation overhead - each `{}` literal triggers memory allocation, hash table setup, and key insertion operations. By reusing pre-allocated structures, we avoid this overhead. The shallow copy is efficient because it only copies references to the string keys/values, not the strings themselves.

## Test Case Performance
The optimization excels across all test scenarios:
- **Known providers**: Fast lookups from module-level dict (most common case)
- **Unknown providers**: Same performance as original for the default fallback
- **Large-scale tests**: The benefits compound - the 1000-iteration tests see cumulative savings from avoiding 1000+ dict constructions
- **Edge cases**: Empty strings, special characters, long names all benefit equally since the optimization is in constant allocation, not string handling

## Impact Assessment
Without `function_references`, we cannot determine call frequency in production, but this is a pure win optimization - it maintains identical behavior (same output structure, key ordering, and semantics) while being strictly faster. Any code path calling this function repeatedly (e.g., batch model configuration, API request handling loops) will see proportional improvements.
@codeflash-ai codeflash-ai Bot added the ⚡️ codeflash Optimization PR opened by Codeflash AI label Feb 18, 2026
@github-actions github-actions Bot added the community Pull Request from an external contributor label Feb 18, 2026
Base automatically changed from EJ/multi-api-support-merge-conflicts to EJ/add-multi-api-support February 18, 2026 17:31
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 18, 2026

Codecov Report

❌ Patch coverage is 46.90265% with 60 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.17%. Comparing base (d8c6480) to head (43f9756).
⚠️ Report is 64 commits behind head on main.

Files with missing lines Patch % Lines
src/backend/base/langflow/api/v1/models.py 33.33% 42 Missing ⚠️
src/backend/base/langflow/agentic/api/router.py 0.00% 8 Missing ⚠️
...backend/base/langflow/services/variable/service.py 78.57% 6 Missing ⚠️
...base/langflow/agentic/services/provider_service.py 25.00% 3 Missing ⚠️
...base/langflow/agentic/services/flow_preparation.py 80.00% 1 Missing ⚠️

❌ Your project status has failed because the head coverage (42.17%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11808      +/-   ##
==========================================
- Coverage   35.23%   32.17%   -3.07%     
==========================================
  Files        1521     1521              
  Lines       72960    72740     -220     
  Branches    10938    10838     -100     
==========================================
- Hits        25711    23407    -2304     
- Misses      45855    47949    +2094     
+ Partials     1394     1384      -10     
Flag Coverage Δ
backend 44.23% <46.90%> (-11.53%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../base/langflow/agentic/flows/langflow_assistant.py 48.00% <100.00%> (-52.00%) ⬇️
...Component/components/modelInputComponent/index.tsx 69.51% <ø> (-0.56%) ⬇️
src/frontend/src/components/ui/input.tsx 56.52% <ø> (ø)
src/frontend/src/constants/providerConstants.ts 100.00% <ø> (ø)
...lers/API/queries/models/use-get-model-providers.ts 84.61% <ø> (ø)
...ProviderModal/components/ModelProvidersContent.tsx 0.00% <ø> (ø)
...als/modelProviderModal/components/ProviderList.tsx 81.48% <ø> (ø)
...c/frontend/src/modals/modelProviderModal/index.tsx 0.00% <ø> (ø)
src/lfx/src/lfx/base/models/model_metadata.py 100.00% <ø> (ø)
src/lfx/src/lfx/base/models/unified_models.py 31.89% <ø> (+1.49%) ⬆️
... and 6 more

... and 113 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Base automatically changed from EJ/add-multi-api-support to main February 27, 2026 16:41
@ogabrielluiz
Copy link
Copy Markdown
Contributor

Closing automated codeflash PR.

@codeflash-ai codeflash-ai Bot deleted the codeflash/optimize-pr11807-2026-02-18T17.19.30 branch March 3, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚡️ codeflash Optimization PR opened by Codeflash AI community Pull Request from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants