GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||
GeezerVison is showing github.com — fix(opencode): Throttle storage writes during streaming to reduce I/O overhead by taetaetae · Pull Request #11328 · anomalyco/opencode Conversation
|
| Aspect | kiro-cli | OpenCode |
|---|---|---|
| API endpoint | Same (q.us-east-1.amazonaws.com) |
Same |
| TTFB | 2-10s | 2-10s |
| Delta handling | Memory only | File write per delta |
| Perceived speed | Fast | Slower |
The bottleneck is in processor.ts:
case "reasoning-delta": if (part.text) await Session.updatePart({ part, delta: value.text }) // This writes to file system on EVERY delta!
Session.updatePart calls Storage.write which does:
await Bun.write(target, JSON.stringify(content, null, 2))
Implement throttled storage writes for reasoning-delta events:
part.text +=)STREAMING_UPDATE_THROTTLE_MS)reasoning-end to ensure data persistenceSTREAMING_UPDATE_THROTTLE_MS constant (50ms)lastUpdateTime, pendingReasoningUpdates)reasoning-delta handler to throttle storage writesreasoning-end always flushes pending updates
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…/O overhead
## Problem
During streaming responses, OpenCode writes to storage (JSON files) on
every reasoning-delta event. With fast streaming APIs, this results in
hundreds of file writes per second, causing:
1. High I/O overhead from frequent file system operations
2. Increased latency between receiving content and displaying it
3. Slower perceived response time compared to native CLI tools
## Analysis
Comparing OpenCode with kiro-cli using the same Kiro API:
- Both receive streaming responses with similar TTFB (2-10s)
- kiro-cli renders directly to terminal (memory only)
- OpenCode writes every delta to storage via Session.updatePart()
The bottleneck is in processor.ts:
```typescript
case "reasoning-delta":
if (part.text) await Session.updatePart({ part, delta: value.text })
// This writes to file system on EVERY delta!
```
## Solution
Implement throttled storage writes for reasoning-delta events:
- Accumulate content in memory (already happening via part.text +=)
- Only flush to storage every 50ms (STREAMING_UPDATE_THROTTLE_MS)
- Always flush on reasoning-end to ensure data persistence
- No change to final content or persistence guarantees
## Expected Impact
- ~20x fewer file writes during streaming
- Reduced I/O overhead
- Faster perceived response time
- No change to final message content
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
we are moving to sqlite |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Tier 1 bug fixes: - Fix O(n²) bash output concatenation with StreamingOutput class (anomalyco#9693) - Fix memory leaks in Bus.once, Format, Plugin, ShareNext, Bootstrap (anomalyco#13514) - Fix FileTime race condition using actual file mtime instead of JS clock - Free memory on compaction prune: clear output/attachments/metadata (anomalyco#7049) - Throttle reasoning-delta storage writes to 50ms intervals (anomalyco#11328) - Handle SIGHUP/SIGTERM to prevent orphaned processes (anomalyco#12718) - Add process.once("close") handler for bash tool reliability Tier 2 features: - Support 1M context window for Anthropic models via beta header (anomalyco#14375) - Input-only token counting for compaction with limit.input models - MCP lazy loading: on-demand tool discovery via mcp_search tool (anomalyco#8771) - MCP servers listed in system prompt when lazy mode enabled - StreamingOutput: output_filter regex for build diagnostics - LSP server cleanup callback for temp directory removal - Extract formatSize utility from uninstall to shared util/format - GitHub CI: fix Bus subscription leak in session event handler Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Slow perceived response time due to excessive storage writes during streaming
There was an error while loading. Please reload this page.