Repository navigation
perf: avoid quadratic start check when streaming from OpenAIResponsesChatGenerator - #13716
Open
deadstrobe5 wants to merge 1 commit into
Open
deadstrobe5 wants to merge 1 commit into
deadstrobe5 wants to merge 1 commit into
Conversation
Contributor
|
@deadstrobe5 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
sjrl
reviewed
Nov 12, 2026
Comment on lines
+881
to
+882
| # A text output starts when no earlier chunk with the same output_index has content. Scanning backwards stops | ||
| # at the previous text delta instead of rescanning every earlier chunk, such as a long reasoning summary. |
Contributor
There was a problem hiding this comment.
Could we drop the "instead of rescanning every earlier chunk" part? Lets keep the comment to what the code does now.
Suggested change
| # A text output starts when no earlier chunk with the same output_index has content. Scanning backwards stops | |
| # at the previous text delta instead of rescanning every earlier chunk, such as a long reasoning summary. | |
| # A text output starts when no earlier chunk with the same output_index has content. | |
| # Scanning backwards stops at the previous text delta. |
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
This branch has not been deployed
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.
Related Issues
Proposed Changes:
_convert_response_chunk_to_streaming_chunksetsStreamingChunk.starton eachresponse.output_text.deltaby checking whether an earlier chunk with the sameoutput_indexalready has content. Onmainit walksprevious_chunksfrom the front for every delta. When a reasoning summary streams before the answer, each text delta first walks past every reasoning chunk, so a stream with R reasoning deltas and T text deltas does about R x T checks.The check now walks
reversed(previous_chunks)with the same predicate,all(c.content == "" ...), and stops at the previous text delta, which is usually the last chunk. The separateall(c.index != chunk.output_index ...)clause goes away becauseall()over no matching chunks is alreadyTrue. The refusal check gets the samereversed();any()gives the same result in either order. No new state.run_asyncandAzureOpenAIResponsesChatGeneratoruse the same function.How did you test it?
pytest -m "not integration"ontest/components/generators/,test/components/agents/,test_query_expander.py,test_llm_ranker.pyandtest/dataclasses/test_streaming_chunk.py: 870 passed.ruff check,ruff format --checkandmypyon the module are clean.ResponseStreamEventsequences were run through the function onmainand on this branch, comparing everyStreamingChunkfield except thereceived_attimestamp. 20,000 random sequences (text, refusal, reasoning and function call deltas, items added and done, interleavedoutput_indexvalues, empty deltas) and full realistic streams gave identical chunks.mainand this branch in one process, alternating order. "Conversion" calls the function over the whole stream.run()andrun_async()use a streaming callback and anhttpx.MockTransportthat serves the SSE body, so SDK parsing is included. Median of 21 runs, min-max in brackets, Python 3.12, openai 3.49.0, shared Linux machine.mainrun(), 1000 reasoning + 2000 text deltasrun_async(), 1000 reasoning + 2000 text deltasrun(), 2000 text deltas, no reasoningNotes for the reviewer
Answers without reasoning barely change, because
mainalready stops early there. The gain grows with the length of the reasoning that precedes the answer. No test onmainpins thestartflag of refusal deltas; none was added, since that line only gainsreversed(). The pre-commit hooks were not run as such; ruff, mypy, codespell andscripts/release_note_backticks.pywere run directly on the changed files.This PR was fully generated with Claude Code, which also ran the tests and benchmarks above.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.