⚡️ Speed up function _args_reference_urls by 25% in PR #10727 (feat/http-stream-mcp)#10925
⚡️ Speed up function _args_reference_urls by 25% in PR #10727 (feat/http-stream-mcp)#10925codeflash-ai[bot] wants to merge 155 commits into
_args_reference_urls by 25% in PR #10727 (feat/http-stream-mcp)#10925Conversation
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
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
…/langflow into feat/http-stream-mcp
The optimization transforms the function from a set intersection approach to an early-exit loop pattern, providing a **25% speedup**.
**Key optimizations:**
1. **Pre-convert URLs to set**: `urls_set = set(urls)` enables O(1) lookups instead of repeated linear searches through the list.
2. **Early exit on first match**: The loop immediately returns `True` when finding the first matching string argument, avoiding unnecessary iteration through remaining args.
3. **Eliminate temporary set creation**: The original code builds a complete set of all string arguments `{arg for arg in args if isinstance(arg, str)}` before checking intersection, which wastes memory and CPU cycles.
**Performance characteristics:**
- **Best case improvement**: When matches occur early in the args sequence, the optimized version can terminate immediately instead of processing all arguments
- **Memory efficiency**: Avoids creating a potentially large temporary set of string arguments
- **Consistent improvement**: Even when no matches exist, the optimized version performs fewer operations per iteration
**Test case analysis shows the optimization excels when:**
- Args contain early matches (exits immediately)
- Large argument lists with mixed types (avoids building full string sets)
- No matches exist (more efficient per-iteration checks)
- Multiple matches present (stops at first rather than finding all)
The line profiler confirms this: the original spends 93.8% of time in the set comprehension + intersection, while the optimized version distributes work more efficiently across the loop with early termination capability.
|
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 project status has failed because the head coverage (39.95%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #10925 +/- ##
==========================================
+ Coverage 32.54% 32.90% +0.36%
==========================================
Files 1371 1371
Lines 63544 63857 +313
Branches 9397 9406 +9
==========================================
+ Hits 20679 21015 +336
+ Misses 41825 41799 -26
- Partials 1040 1043 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
dac5be9 to
b943b6e
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.📄 25% (0.25x) speedup for
_args_reference_urlsinsrc/backend/base/langflow/api/v1/mcp_projects.py⏱️ Runtime :
1.00 millisecond→802 microseconds(best of5runs)📝 Explanation and details
The optimization transforms the function from a set intersection approach to an early-exit loop pattern, providing a 25% speedup.
Key optimizations:
Pre-convert URLs to set:
urls_set = set(urls)enables O(1) lookups instead of repeated linear searches through the list.Early exit on first match: The loop immediately returns
Truewhen finding the first matching string argument, avoiding unnecessary iteration through remaining args.Eliminate temporary set creation: The original code builds a complete set of all string arguments
{arg for arg in args if isinstance(arg, str)}before checking intersection, which wastes memory and CPU cycles.Performance characteristics:
Test case analysis shows the optimization excels when:
The line profiler confirms this: the original spends 93.8% of time in the set comprehension + intersection, while the optimized version distributes work more efficiently across the loop with early termination capability.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-pr10727-2025-12-08T15.44.55and push.