Conversation
Signed-off-by: 0YHR0 <97868579@qq.com>
✅ Deploy Preview for theagentrouter canceled.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Sep 14, 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.
Description
Anthropic stream folding repeatedly concatenates growing text, thinking, and tool-argument strings. Each delta copies the entire accumulated prefix, causing quadratic allocation for long responses, including GenAI traces with message-content capture disabled.
Accumulate fragments in per-block
strings.Builderbuffers while preserving initial content, interleaved indices, block replacement, and tool argument parsing at block stop. Add regression tests and a fold-only benchmark. This removes repeated prefix copies but does not implement a bounded-memory recorder or stop retaining source chunks.Related Issues/PRs (if applicable)
Concrete performance improvement supporting #2668. Independent of the proposed configuration and recorder-interface changes, and of the usage-alias fix in #2635.
Special notes for reviewers (if applicable)
Using the same sampled-span benchmark from #2668 (1 MiB text, 8,192 deltas, content capture off), cumulative allocation fell from 4,330,508,344 B/op to 8,048,784 B/op, approximately a 99.8% reduction. These are second runs with
-benchtime=1x -count=2, not peak heap or statistically rigorous latency claims.Local validation uses Go 1.26.6 / Windows amd64 in the isolated
1899d8d4checkout used for the proposal baseline, with this implementation and tests applied.go test ./internal/apischema/anthropic ./internal/tracing -count=1and the full-span benchmark pass. The PR is based on current main; its Go 1.27.1 validation remains for CI.Developed with assistance from OpenAI Codex.