Skip to content

perf(http): stream finite SSE responses incrementally - #225

Merged
MisterVVP merged 2 commits into
dev-optimize-streaming-response-latenciesfrom
dev-make-finite-streaming-incremental-for-sse
Aug 26, 2026
Merged

MisterVVP merged 2 commits into
dev-optimize-streaming-response-latenciesfrom
dev-make-finite-streaming-incremental-for-sse

Conversation

@MisterVVP

@MisterVVP MisterVVP commented Aug 26, 2026 •

Copy link
Copy Markdown
Owner

Motivation

  • Finite HTTP and JSON-RPC SSE responses were being fully buffered server-side, delaying first-event delivery and regressing finite-stream first-event latency.
  • Make finite SendStreamingMessage responses truly incremental so the first event is serialized and sent as soon as ServerStreamSession::Next() produces it while preserving envelope/ordering/semantics.

Description

  • Write response status line and headers (including Transfer-Encoding: chunked) to the transport immediately for reusable streaming responses, then invoke the stream writer; emit the terminal 0\r\n\r\n only after successful completion and avoid emitting it if the writer fails (src/server/transport/http_adapter.cpp).
  • Rework ChunkedByteTransport to avoid large temporary concatenations by formatting the chunk-size into stack storage and performing direct prefix, payload, and terminator writes to the underlying transport (src/server/transport/http_adapter.cpp).
  • Replace REST finite-stream buffering in BuildStreamingResponse() with a stream_writer that pulls one StreamResponse, serializes exactly one SSE event, writes it immediately, then requests the next event; session lifetime is moved into writer-owned state (src/server/transport/rest_transport.cpp).
  • Replace JSON-RPC finite-stream buffering with StreamFiniteJsonRpcSseEvents() that builds one JSON-RPC success envelope per event (preserving request id), emits exactly one SSE event, writes it immediately, and repeats until completion (src/server/transport/json_rpc_server_transport.cpp).
  • Added deterministic unit tests that assert headers are visible before the first body event, that finite REST streams write each event before requesting the next and propagate producer failure, and that JSON-RPC finite streams preserve request id and stream incrementally (tests/unit/http_adapter_test.cpp, tests/unit/rest_transport_test.cpp, tests/unit/json_rpc_server_transport_test.cpp).
  • Did not add coroutine machinery because ServerStreamSession::Next() already provides the correct incremental pull semantics and HttpByteTransport::Write() remains synchronous.

@MisterVVP MisterVVP added the codex Automatic label added by codex agent. Should not be used label Aug 26, 2026 — with ChatGPT Codex Connector
@MisterVVP MisterVVP self-assigned this Aug 26, 2026
@MisterVVP MisterVVP added AI agent AI agent contribution performance Performance improvement related tasks based on benchmark results. Performance tests changes. and removed codex Automatic label added by codex agent. Should not be used labels Aug 26, 2026
@MisterVVP
MisterVVP merged commit 08c4124 into dev-optimize-streaming-response-latencies Aug 26, 2026
17 checks passed
@MisterVVP
MisterVVP deleted the dev-make-finite-streaming-incremental-for-sse branch August 26, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI agent AI agent contribution performance Performance improvement related tasks based on benchmark results. Performance tests changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant