Repository navigation
perf(callbacks): skip the stream serialization copy for read-only callbacks - #1052
Merged
Merged
Conversation
tyaroshko
force-pushed
the
perf/jsonpath-cache
branch
from
October 26, 2026 12:52
bca4347 to
c6c211b
Compare
delamainer
force-pushed
the
perf/stream-callback-copy
branch
from
October 30, 2026 09:51
480e98d to
afd0a2c
Compare
delamainer
changed the base branch from
main
to
perf/llm-streaming-throughput
October 30, 2026 09:51
delamainer
force-pushed
the
perf/stream-callback-copy
branch
2 times, most recently
from
November 2, 2026 14:07
09894b5 to
07db608
Compare
delamainer
force-pushed
the
perf/llm-streaming-throughput
branch
from
November 2, 2026 14:07
ae513ca to
ac69bbd
Compare
delamainer
force-pushed
the
perf/stream-callback-copy
branch
from
November 2, 2026 14:35
07db608 to
b271ab3
Compare
Coverage Report •
|
|||||||||||||||||||||||||||||||||||||||||||||
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
#1039 serializes a streaming node once per
stream_serialization_scopeand hands each stream callback a copy of that dict on every event, so a callback editing it cannot change what the next one receives. The copy (_copy_serialized) walks the whole node serialization, prompt included, once per callback per chunk. A py-spy profile of the runtime put it at 16 ms of CPU per streamed agent run and 7 ms per streamed LLM run.dynamiq's own stream callbacks only read a few keys of
serialized:StreamingQueueCallbackHandlerreadsid,name,group,typeandstreaming.event, andAgentStreamingParserCallbackreadsgroupandid. A new decorator,reads_stream_serialization_only, marks such anon_node_execute_stream, andrun_on_node_execute_streamgives a marked callback the scope's serialization itself instead of a copy.on_node_execute_streamreceives copies again unless it marks its override too.StreamingIteratorCallbackHandlerandAsyncStreamingIteratorCallbackHandlerinherit the queue handler's method and its mark.Measurements
Micro-benchmark:
run_on_node_execute_streamwith aStreamingQueueCallbackHandlerinside a scope, for an OpenAI node with a 1 KB system prompt, CPU per event: 15.2 µs before, 4.3 µs 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 on dynamiq's default LiteLLM transport, as production runs. 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:
On the SDK transport, before the rebase: the same benchmark. Two images from the same runtime code, one with this branch's base (#1049 at
bca4347) and one with this commit, 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 every round, for four rounds.CPU per run, the mean of the four rounds:
_copy_serialized(16 ms and 7 ms). A worker sustains about 1000 / (CPU ms per run) runs a second, so about 12 streamed agent runs a second instead of 10.Tests
tests/unit/nodes/test_stream_serialization.pyadds:to_dict()for the scope;The existing tests of #1039's isolation still pass, as do the unit and integration suites.