⚡️ Speed up function is_local_ip by 12% in PR #9891 (lf-auto-add-mcp-servers)#10045
⚡️ Speed up function is_local_ip by 12% in PR #9891 (lf-auto-add-mcp-servers)#10045codeflash-ai[bot] wants to merge 72 commits into
is_local_ip by 12% in PR #9891 (lf-auto-add-mcp-servers)#10045Conversation
Moved MCP-related utility functions (auto_configure_starter_projects_mcp, get_project_sse_url, get_url_by_os) from mcp_projects.py to a new dedicated utils/mcp/config_utils.py module for better code organization and maintainability. Added __init__.py files for new utils submodules and updated imports accordingly. Also updated documentation and comments for clarity. Minor docstring update in settings/base.py.
Added support for configurable default authentication type when auto-registering MCP servers for new projects, including handling for 'none', 'apikey', and unimplemented 'oauth' types. MCP server names are now updated on project rename, and corresponding MCP servers are deleted when projects are removed. Introduced 'default_mcp_auth_type' setting to control authentication mode for auto-added MCP servers.
Replaces the 'current_port' field with 'runtime_port' in settings to clarify its temporary, system-managed nature. Updates all references and documentation to reflect the new field name and its intended use until strict port enforcement is implemented.
Added a TODO comment to improve the method for determining the position of the SSE URL in the argument list within validate_mcp_server_for_project.
…-ai/langflow into lf-auto-add-mcp-servers
…tings pages for testing purposes 🔧 (frontend): add convertTestName utility function for converting test names to lowercase with hyphens 🔧 (frontend): add cleanOldFolders utility function to remove old folders in testing environment 🔧 (frontend): add navigateSettingsPages utility function to navigate to specific settings pages in testing
…flow into lf-auto-add-mcp-servers
…havior ✨ (use-patch-flows-mcp.ts): add retry: 0 option to improve mutation behavior ✨ (use-patch-install-mcp.ts): add retry: 0 option to improve mutation behavior ✨ (use-patch-mcp-server.ts): add retry: 0 option to improve mutation behavior 📝 (mcp-server-starter-projects.spec.ts): add test to prevent adding duplicate mcp servers from starter projects
…orTimeout to 5000ms for stability ⬆️ (starter-projects.spec.ts): adjust timeout value to 5000 * 3 for better performance and reliability
The optimization adds fast-path string comparisons for the most common loopback IP addresses (`127.0.0.1` and `::1`) before falling back to the expensive `ip_address()` constructor. **Key changes:** - Added `if ip_str == "127.0.0.1" or ip_str == "::1": return True` before the try-catch block - This bypasses the costly `ip_address()` call for these frequent cases **Why this is faster:** The `ip_address()` function is expensive (taking ~22,500ns per call according to profiling) because it performs comprehensive parsing and validation. Simple string equality checks are orders of magnitude faster (~400-500ns). **Performance impact:** - Line profiler shows 734 hits on the new fast-path condition, meaning 734 calls avoided the expensive `ip_address()` construction - The `ip_address()` line dropped from 6,145 hits to 5,411 hits (734 fewer calls) - Total runtime reduced from 161.661ms to 148.718ms (11% speedup) **Best for:** Applications that frequently check common loopback addresses like "127.0.0.1" and "::1", which are the most typical localhost representations. The optimization maintains full correctness while providing significant speedup for these common cases, with no performance penalty for other IP addresses.
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the 🧪 Early access (Sonnet 4.5): enabledWe are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience. Note:
Comment |
|
Codecov Report❌ Patch coverage is ❌ Your project status has failed because the head coverage (47.01%) is below the target coverage (55.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #10045 +/- ##
==========================================
+ Coverage 23.68% 24.12% +0.44%
==========================================
Files 1090 1091 +1
Lines 39766 40014 +248
Branches 5542 5543 +1
==========================================
+ Hits 9417 9655 +238
- Misses 30178 30188 +10
Partials 171 171
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Closing automated codeflash PR. |



⚡️ This pull request contains optimizations for PR #9891
If you approve this dependent PR, these changes will be merged into the original PR branch
lf-auto-add-mcp-servers.📄 12% (0.12x) speedup for
is_local_ipinsrc/backend/base/langflow/api/v1/mcp_projects.py⏱️ Runtime :
19.4 milliseconds→17.3 milliseconds(best of82runs)📝 Explanation and details
The optimization adds fast-path string comparisons for the most common loopback IP addresses (
127.0.0.1and::1) before falling back to the expensiveip_address()constructor.Key changes:
if ip_str == "127.0.0.1" or ip_str == "::1": return Truebefore the try-catch blockip_address()call for these frequent casesWhy this is faster:
The
ip_address()function is expensive (taking ~22,500ns per call according to profiling) because it performs comprehensive parsing and validation. Simple string equality checks are orders of magnitude faster (~400-500ns).Performance impact:
ip_address()constructionip_address()line dropped from 6,145 hits to 5,411 hits (734 fewer calls)Best for: Applications that frequently check common loopback addresses like "127.0.0.1" and "::1", which are the most typical localhost representations. The optimization maintains full correctness while providing significant speedup for these common cases, with no performance penalty for other IP addresses.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-pr9891-2025-09-30T16.46.22and push.