Skip to content

Improve SSE chunk buffering performance - #1117

Merged
Kludex merged 2 commits into
mainfrom
agent/improve-sse-chunk-buffering
Aug 6, 2026
Merged

Improve SSE chunk buffering performance#1117
Kludex merged 2 commits into
mainfrom
agent/improve-sse-chunk-buffering

Conversation

@Kludex

@Kludex Kludex commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Accumulate incomplete SSE lines as string fragments and join them when a line separator arrives.
  • Track the pending UTF-8 byte count incrementally while preserving max_event_size behavior.
  • Add coverage for events split across many chunks.

Motivation

Reduce repeated copying and rescanning when SSE event lines are delivered in highly fragmented streams. This keeps parsing performance predictable without changing the public API or event semantics.

Validation

  • pytest tests/httpx2/test_sse.py -q
  • pytest tests/test_benchmark.py::test_bench_sse_many_chunks_without_line_separator -q
  • Ruff formatting and lint checks
  • mypy

Review in cubic

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

@codspeed-hq

codspeed-hq Bot commented Aug 6, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×35

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 15 untouched benchmarks
⏩ 7 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation test_bench_sse_many_chunks_without_line_separator 3,071.8 ms 86.9 ms ×35

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing agent/improve-sse-chunk-buffering (614b433) with main (ad141d8)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

@Kludex
Kludex enabled auto-merge (squash) August 6, 2026 08:56
@Kludex
Kludex merged commit cbfc0e0 into main Aug 6, 2026
17 checks passed
@Kludex
Kludex deleted the agent/improve-sse-chunk-buffering branch August 6, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant