Skip to content

perf(cli): guard large-file reads and avoid sync patch I/O#9919

Open
kilo-code-bot[bot] wants to merge 1 commit intomainfrom
fix/read-perf-guards
Open

perf(cli): guard large-file reads and avoid sync patch I/O#9919
kilo-code-bot[bot] wants to merge 1 commit intomainfrom
fix/read-perf-guards

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

@kilo-code-bot kilo-code-bot Bot commented May 5, 2026

Addresses review remarks about memory blowup and event-loop blocking on large file reads.

Changes

  • encoding.ts: Cap jschardet detection to a 64 KB prefix. Valid UTF-8 bytes still short-circuit before detection; only non-UTF-8 inputs hit the sampler, so accuracy is unaffected.
  • tool/read.ts: Reject files over 10 MB before calling Encoding.read, since the encoding-aware path buffers the whole file for BOM detection / iconv decode (a regression from the prior createReadStream path for multi-GB files).
  • patch/index.ts + tool/apply_patch.ts: Convert deriveNewContentsFromChunks to async and replace Encoding.readSync with Encoding.read so the apply-patch flow no longer does blocking I/O on the Node event loop. All callers already live in async contexts.

@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot Bot commented May 5, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/opencode/src/patch/index.ts
  • packages/opencode/src/tool/apply_patch.ts

Reviewed by gpt-5.5-2026-04-23 · 242,365 tokens

Cap jschardet detection to a 64 KB prefix, reject reads of files
larger than 10 MB in the read tool, and make deriveNewContentsFromChunks
async so apply_patch no longer blocks the event loop on large files.
@kilo-code-bot kilo-code-bot Bot force-pushed the fix/read-perf-guards branch from 7650dc9 to 55b19b8 Compare May 5, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant