backport: feat(ai): optimize text accumulation runtime to O(N)#15906
backport: feat(ai): optimize text accumulation runtime to O(N)#15906aayush-kapoor wants to merge 1 commit into
Conversation
Validation results + report of a sibling site this PR does not coverValidated this PR (specifically the v6 backport, #15906) against an in-the-wild reproduction of the bug it was filed for. Short version: the PR is correctly written and a real improvement, but the bug still fires on tool-input-heavy workloads because of a third O(N²) site in the same file that this PR does not address. Posting here so you can decide whether to expand scope before merging or land it with a tracking issue. Stack used
Results
Max-step distribution per group (sorted desc):
Every single run, in every config, has at least one step taking 48–120s. In a healthy run, no individual LLM step should take >15s on this model. The signature is the bug still firing — just attenuated. The third site
case 'tool-input-delta': {
const partialToolCall = state.partialToolCalls[chunk.toolCallId];
…
partialToolCall.text += chunk.inputTextDelta; // ← same pattern as text-delta / reasoning-delta
const { value: partialArgs } = await parsePartialJson(
partialToolCall.text, // ← forces flatten on every chunk
);Same Why a naïve
|
|
Added benchmark that reproduces quadratic effect with high number of chunks / small chunk size: However, it does not show that the changes here fix it. |
Background
manual backport for #15897
Checklist
pnpm changesetin the project root)