Repository navigation
Conversation
…apIterable The reasoning and summary chunk paths subscribed an inner Flux per chunk (deferContextual + fromIterable), costing one Reactor subscription handshake per streamed chunk; at high stream counts that serial handoff dominates end-to-end latency (~2x at 500 concurrent streams, measured in agentscope-ai#3929). Generate events synchronously per chunk and flatten with concatMapIterable instead. The subscriber context is constant along the chunk chain, so it is now captured once per stream for hook delivery rather than once per chunk. Sequential per-chunk processing, ordering, and completion/error behavior are unchanged; ordering and hook-context inheritance are pinned by tests. Refs agentscope-ai#3929
|
Results for #4197, same method as the #3961/#4088 runs: full Maven builds of parent ( Timing: reproduced — and larger than the historical figure. Summary from our side: independent measurement, no objection. Of the three changes, this one is the largest single gain we measured on current main, with no change in counts, completion, or TTFT direction. All three changes from #3929 are now implemented and independently verified as far as our harness can tell. |
|
Hi @jujn, when you have a chance, could you take a look at this PR? It’s been open for a few weeks, and I’d appreciate any feedback or guidance on what would help move it forward. The existing checks are passing, and the independent benchmark results are in the thread above. A few other PRs are also awaiting review: #3786, #3889, #4065, and #3457. No need to look at all of them at once. If there’s anything I should change or test before review, I’m happy to follow up. Thanks for your time! |
Summary
Third and last measured change from #3929: generate streaming chunk events synchronously and flatten with
concatMapIterable, instead of subscribing an innerFluxper chunk.Problem
Both chunk paths (
preparedModelCallStream,preparedSummaryModelCallStream) processed every streamed chunk insideFlux.deferContextual(...)and returnedFlux.fromIterable(events): one Reactor subscription handshake per chunk (deferContextual + inner fromIterable), serial per chunk. At high stream counts that handoff dominates end-to-end latency — #3929 measured ~2x inflation at 500 concurrent streams, and the reporter's fork attributed −7.2 s per 500-chain mean to this change alone. After the first two changes landed (#3961, #4088), the reporter's re-benchmark on current main (2026-11-14) still attributes the remaining ~24.6 s gap to their fork reference to this third change.Solution
concatMap+deferContextual+fromIterablewithconcatMapIterable(chunk -> { ... })in both chunk paths..contextWrite(ctx -> ctx.putAll(parentCtx))on the hook call) instead of once per chunk.untilInterruptedstays in place; the mapper drains synchronously during concat drain).Tests
New
ReActAgentChunkFlattenTest:ModelCallStartEvent/ModelCallEndEventpresent.contextWrite: hook still sees context written at subscription time — pins the capture-once context semantics.Full
agentscope-coresuite: 3453 tests, 0 failures (2 pre-existing Windows symlink-privilege environment errors inDangerousPathBypassTest, unrelated to this change — they fail in test setup before any agent code runs).The end-to-end number belongs to @realreus319's harness, same as the first two changes.
Refs #3929