Skip to content

perf(mcp): eliminate SSE buffer churn in streaming parser - #1153

Merged
henrypark133 merged 1 commit into
nearai:stagingfrom
G7CNF:codex/issue-1142-sse-buffer
Mar 14, 2026
Merged

henrypark133 merged 1 commit into
nearai:stagingfrom
G7CNF:codex/issue-1142-sse-buffer

Conversation

@G7CNF

@G7CNF G7CNF commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • replace per-chunk trailing-slice reallocation (buffer = buffer[remaining_start..].to_string()) with in-place compaction (buffer.drain(..remaining_start))
  • keep SSE parser behavior unchanged while removing repeated allocations in the hot streaming loop

Why

Issue #1142 identified avoidable allocation churn in parse_sse_response for large/many chunks. Reallocating a new String each loop iteration is unnecessary and can degrade throughput.

This change keeps the same parser semantics but reuses the existing buffer capacity.

Closes #1142

Validation

  • cargo fmt --all
  • cargo test -p ironclaw tools::mcp::http_transport::tests::test_http_transport_creation -- --nocapture
  • cargo clippy -p ironclaw --all-targets -- -D warnings

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions github-actions Bot added scope: tool/mcp MCP client size: XS < 10 changed lines (excluding docs) risk: medium Business logic, config, or moderate-risk modules contributor: experienced 6-19 merged PRs labels Mar 13, 2026

@henrypark133 henrypark133 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: good small perf cleanup

This keeps the SSE parser behavior the same while removing avoidable allocation churn in the hot loop.

Positives:

  • drain(..remaining_start) is a straightforward replacement for the previous trailing-slice reallocation.
  • The change is extremely small and easy to reason about.
  • Meaningful CI is green.

No blocking issues from my side.

@henrypark133
henrypark133 merged commit 8753c48 into nearai:staging Mar 14, 2026
14 checks passed
@G7CNF
G7CNF deleted the codex/issue-1142-sse-buffer branch March 15, 2026 14:31
@ironclaw-ci ironclaw-ci Bot mentioned this pull request Mar 17, 2026
bkutasi pushed a commit to bkutasi/ironclaw that referenced this pull request Mar 28, 2026
drchirag1991 pushed a commit to drchirag1991/ironclaw that referenced this pull request Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: experienced 6-19 merged PRs risk: medium Business logic, config, or moderate-risk modules scope: tool/mcp MCP client size: XS < 10 changed lines (excluding docs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HIGH] **O(n²) string allocations in hot SSE parsing path**: In http_transport.rs, the

2 participants