-
Notifications
You must be signed in to change notification settings - Fork 8.2k
⚡️ Speed up function config_contains_server_url by 97% in PR #10727 (feat/http-stream-mcp)
#10748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
fix tests refactor mcp and mcp_projects backwards compat with SSE transport provide streamable http option for json mcp config remove streamable_http mgmt and update tests
The optimization achieves a **97% speedup** by fundamentally changing how URL matching is performed in the `_args_reference_urls` function. The key change replaces an expensive `any()` generator expression with efficient set operations.
**Primary Optimization:**
The original code used `any((url == last_arg) or (url in args_set) for url in urls)` which performs individual comparisons for each URL. The optimized version uses `bool(args_set.intersection(urls)) or last_arg in urls`, leveraging Python's highly optimized C-level set intersection operation.
**Performance Impact:**
- **Original**: 64.7ms spent in the critical line (93% of function time)
- **Optimized**: 4.6ms spent in the critical line (49% of function time)
- This represents a ~14x improvement on the bottleneck operation alone
**Why This Works:**
Set intersection (`args_set.intersection(urls)`) is implemented in C and processes multiple items simultaneously, while the generator expression processes URLs one-by-one in Python bytecode. The `or last_arg in urls` fallback handles the special case efficiently when no general intersection exists.
**Minor Optimization:**
The code also extracts `server_config.get("args", [])` into a variable to avoid repeated dictionary lookups, though this has minimal impact compared to the set intersection change.
**Test Case Performance:**
The optimization particularly excels with large-scale test cases involving many servers, URLs, or arguments, where set operations provide the most benefit over iterative comparisons. Basic functionality and edge cases maintain identical behavior while running significantly faster.
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat/http-stream-mcp #10748 +/- ##
========================================================
- Coverage 32.66% 32.65% -0.01%
========================================================
Files 1368 1368
Lines 63685 63686 +1
Branches 9367 9367
========================================================
- Hits 20801 20798 -3
- Misses 41854 41858 +4
Partials 1030 1030
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
d053266 to
9f7014d
Compare
⚡️ This pull request contains optimizations for PR #10727
If you approve this dependent PR, these changes will be merged into the original PR branch
feat/http-stream-mcp.📄 97% (0.97x) speedup for
config_contains_server_urlinsrc/backend/base/langflow/api/v1/mcp_projects.py⏱️ Runtime :
9.30 milliseconds→4.72 milliseconds(best of66runs)📝 Explanation and details
The optimization achieves a 97% speedup by fundamentally changing how URL matching is performed in the
_args_reference_urlsfunction. The key change replaces an expensiveany()generator expression with efficient set operations.Primary Optimization:
The original code used
any((url == last_arg) or (url in args_set) for url in urls)which performs individual comparisons for each URL. The optimized version usesbool(args_set.intersection(urls)) or last_arg in urls, leveraging Python's highly optimized C-level set intersection operation.Performance Impact:
Why This Works:
Set intersection (
args_set.intersection(urls)) is implemented in C and processes multiple items simultaneously, while the generator expression processes URLs one-by-one in Python bytecode. Theor last_arg in urlsfallback handles the special case efficiently when no general intersection exists.Minor Optimization:
The code also extracts
server_config.get("args", [])into a variable to avoid repeated dictionary lookups, though this has minimal impact compared to the set intersection change.Test Case Performance:
The optimization particularly excels with large-scale test cases involving many servers, URLs, or arguments, where set operations provide the most benefit over iterative comparisons. Basic functionality and edge cases maintain identical behavior while running significantly faster.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-pr10727-2025-11-27T04.36.16and push.