Description
Looking at the code in packages/opencode/src/tool/read.ts (lines 94-108):
The key issue here is:
- Line 94: const lines = await file.text().then((text) => text.split("\n"))
This will load the ENTIRE file into memory first, then split it by \n. If you have a huge file with no line breaks:
- The entire file will be read into memory as a single string
- split("\n") will create an array with just 1 element (the entire file content)
- This means memory usage equals the size of the huge file
- Line 99-100: There's a MAX_LINE_LENGTH of 2000 characters, but this only truncates individual lines after they're already in memory.
- Line 102-104: There's a MAX_BYTES limit of 50KB (line 14: const MAX_BYTES = 50 * 1024), but this check happens AFTER the file is already fully loaded into memory.
I see significant memory and performance risks with this approach. The current implementation will struggle with large, non-delimited files, potentially causing system instability or excessive memory consumption. The code lacks efficient streaming or chunked reading mechanisms that could handle such edge cases gracefully.
The file's entire contents get loaded before any processing occurs, which defeats the purpose of the byte limit check. This means for a massive 1GB file, the entire gigabyte will occupy memory, only to have most of it immediately discarded. This approach is fundamentally flawed and inefficient for handling large files.
The file index.ts reveals similar issues in its status() function, which reads entire file contents without considering potential memory overhead.
Plugins
No response
OpenCode version
No response
Steps to reproduce
- Create a file bigger then available RAM
- Ask opencode to read first line
Screenshot and/or share link
No response
Operating System
No response
Terminal
No response
Description
Looking at the code in packages/opencode/src/tool/read.ts (lines 94-108):
The key issue here is:
This will load the ENTIRE file into memory first, then split it by \n. If you have a huge file with no line breaks:
I see significant memory and performance risks with this approach. The current implementation will struggle with large, non-delimited files, potentially causing system instability or excessive memory consumption. The code lacks efficient streaming or chunked reading mechanisms that could handle such edge cases gracefully.
The file's entire contents get loaded before any processing occurs, which defeats the purpose of the byte limit check. This means for a massive 1GB file, the entire gigabyte will occupy memory, only to have most of it immediately discarded. This approach is fundamentally flawed and inefficient for handling large files.
The file index.ts reveals similar issues in its status() function, which reads entire file contents without considering potential memory overhead.
Plugins
No response
OpenCode version
No response
Steps to reproduce
Screenshot and/or share link
No response
Operating System
No response
Terminal
No response