perf(opencode): reduce redundant summary and queue overhead - #21507
perf(opencode): reduce redundant summary and queue overhead#21507GuestAUser wants to merge 3 commits into
Conversation
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PR FoundPR #20303: refactor(opencode): optimize doom loop detection, summary debounce, parallel plugin events This PR may be related because it also addresses summary debouncing/optimization in opencode, which overlaps with PR #21507's work on reducing redundant summary calls and processor cleanup. However, the exact relationship (whether closed, merged, or addressing different aspects) should be verified. PR #19237: perf(opencode): reduce streaming latency and request overhead This PR addresses similar hot-path performance concerns in opencode streaming, though focused on a different area. |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Summary
SessionSummary.summarize()calls so concurrent summary work shares one computation instead of re-reading messages and re-running snapshot diffs in parallelAsyncQueue'sArray.shift()dequeue path with a head-index queue to remove O(n) copies from hot SSE / event / TUI delivery pathsSessionProcessorcleanup by using the in-memoryctx.toolcallsmap that already tracks active tool callsWhy
The current opencode hot path still pays for a few avoidable costs in high-frequency paths:
{sessionID, messageID}pair, which duplicates message hydration and diff workshift()costs during sustained event deliveryNone of these change the user-visible model behavior. The goal here is to shave redundant work from core loop infrastructure while preserving fault tolerance and existing tool-loop semantics.
What changed
1. Single-flight session summary work
packages/opencode/src/session/summary.tsInstanceStateEffectCache.make()to share one in-flight summarize operation per[sessionID, messageID]packages/opencode/test/session/summary.test.ts2. O(1) queue dequeue path
packages/opencode/src/util/queue.tsshift()packages/opencode/test/util/queue.test.ts3. Processor cleanup avoids redundant reads
packages/opencode/src/session/processor.tsctx.toolcallsmap rather than rereading all parts for the assistant messageScope
This PR is intentionally limited to
packages/opencode/**hot-path infrastructure.It does not include the unrelated local
packages/console/**changes currently present in my working tree.Validation
Typecheck
Run from
packages/opencode:bun typecheckTargeted tests
Run from
packages/opencode:bun test test/session/summary.test.ts test/util/queue.test.ts test/session/processor-effect.test.tsResult:
Manual QA
Run from
packages/opencode:bun -e 'import { AsyncQueue } from "./src/util/queue"; const q = new AsyncQueue(); q.push("a"); q.push("b"); console.log([await q.next(), await q.next()].join(","))'a,bSessionSummary.layersummary_messages:1summary_calls:1Microbench checks
Run from
packages/opencode:shift:18.13msidx:12.73mswarm_same:24.12msvary_agent:32.38msTrade-offs / things to watch
Follow-up measurement plan
After merge, the next useful measurement is an end-to-end agent-loop benchmark on a fixed fixture repo that captures:
That follow-up would quantify how much these micro-optimizations move real session throughput under realistic load.