Repository navigation
perf(llms): stream OpenAI SDK chunks as dicts without building their models - #1053
Merged
Merged
Conversation
delamainer
force-pushed
the
perf/openai-raw-chunks
branch
from
October 30, 2026 09:51
cb706ff to
00beca7
Compare
delamainer
changed the base branch from
main
to
perf/llm-streaming-throughput
October 30, 2026 09:51
delamainer
force-pushed
the
perf/openai-raw-chunks
branch
from
October 30, 2026 09:59
00beca7 to
051d26b
Compare
Coverage Report •
|
||||||||||||||||||||||||||||||||||||||||
delamainer
force-pushed
the
perf/openai-raw-chunks
branch
from
November 2, 2026 14:07
af60fd7 to
0dd7e27
Compare
tyaroshko
approved these changes
Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The OpenAI SDK transport (#1039) let the SDK build a
ChatCompletionChunkpydantic model for every streamed chunk, and the LLM node then dumped each one back to a dict for the stream callbacks. Building and dumping cost about 25 µs per chunk, most of a streamed call's chunk handling: a py-spy profile of the runtime put 8–10 ms per streamed LLM and agent run on it.Streams now ask the SDK for each chunk's JSON as it is, through its documented raw-response API (
with_raw_response.create(...).parse(to=Stream[object])), and_chunk_dictfills in the dict to exactly whatChatCompletionChunk.model_dump()returned, in about 1 µs:moderation(one of several models), still goes through the SDK.What the callbacks receive, and so what clients receive in stream events, does not change. Around it:
_build_streamed_responsenow also gets the stream).Stacked on #1039.
Measurements
Micro-benchmark: a streamed call of 300 chunks through the node with a mock transport, CPU per call: 14.3 ms before, 5.9 ms after.
End to end in the runtime, after dynamiq 0.70.0: the mono runtime benchmark (
services/runtime/benchmarkin dynamiq-ai/mono#1565) on the dev cluster. Two images of the runtime from mono main, one with #1039 merged up to dynamiq main (acabdcb) and one with this commit rebased on it, both withDYNAMIQ_OPENAI_NATIVE_SDK=true. One uvicorn worker with 1 CPU requested and 2 as the limit, each workload at two fixed rates of real runs (gpt-5.6-luna). Both images ran at the same time on two nodes of the same type, so they saw the same LLM latency, and swapped nodes for the second round.CPU per run, the mean of the two rounds:
bca4347, the same comparison gave −24% / −27% for the agent, −24% / −23% for a streamed call and −19% for a streamed agent run.Tests
tests/unit/nodes/llms/test_openai_native_sdk.py:_chunk_dictreturns whatChatCompletionChunk.construct(**data).model_dump()does, compared as JSON so key order counts, for text, tool call, usage, logprob, extra-key, missing-field andmoderationchunks;ChatCompletionChunk;The SDK tests pass with openai 2.24 (dynamiq's lock) and 2.43 (the runtime's), and the unit and integration suites pass.