anomalyco / anomalyco/opencode
Core tool-output suffix previews allocate full character arrays
@neriousy is already working on this.
Since Sep 5, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
Core tool-output previews allocate character arrays proportional to the sampled text just to retain a short suffix. takeSuffix() in packages/core/src/tool-output-store.ts uses Array.from(input).toReversed() and then prepends retained characters with unshift().
For long single-line output, line sampling does not reduce the input, so this work scales with the entire text even though the default suffix budget is only about 25 KiB. The preview is correct, but unnecessarily expensive to produce.
Steps to reproduce
- Use the existing
withStorefixture inpackages/core/test/tool-output-store.test.tswith default limits. - Call
store.bound()with one text content item containing"a".repeat(1024 * 1024)and empty structured metadata. - Profile repeated calls after warmup. The suffix path creates and reverses a full character array before retaining the small tail.
The expected behavior is to scan backward only as far as the suffix byte budget requires, preserving the current preview and saved full output. Calls whose sampled text already fits the budget do not need this optimization.
Related work
The closed, unmerged PR #37968 includes the same suffix optimization within broader structured-output changes targeting v2. The current dev still has the array-based implementation. This issue tracks only that suffix allocation cost, not structured-output limits or general memory growth.
OpenCode version
Source baseline 5cf9f517cfec3ef68d3e68a12a6a4b3163947f44 (1.18.28); the affected implementation is unchanged at upstream dev 5b1e31988ed74b821b3a7ca6647188446992aafc.
Operating System
macOS arm64, Bun 1.3.14.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.