fix(opencode): reduce memory allocations in read tool#13676
Closed
SeanThomasWilliams wants to merge 12 commits intoanomalyco:devfrom
Closed
fix(opencode): reduce memory allocations in read tool#13676SeanThomasWilliams wants to merge 12 commits intoanomalyco:devfrom
SeanThomasWilliams wants to merge 12 commits intoanomalyco:devfrom
Conversation
Contributor
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13669
Reduce transient memory allocations in ReadTool:
file.slice(0, estimate).text()instead offile.text()for text reads (issue item 1)file.slice(0, 4096).arrayBuffer()(issue item 2)readdirfor missing-file suggestionsItem 3 from the issue (image/PDF base64 size guard) is not addressed here — capping inline images would be a feature regression since all sizes currently work. That can be revisited separately if needed.
Tests
Memory verification
100MB text file read, peak RSS measured by polling the child process VmRSS.
The opencode launcher spawns a native binary child, so
pgrep -Pfinds the actual process to sample.Results (3 runs each):
Small file control (100 lines) — no regression:
Edge cases verified
Error: Offset 9999 is out of rangeError: Cannot read binary file