Reduce memory usage by avoiding full file reads#5
Merged
randall77 merged 1 commit intorandall77:masterfrom Apr 6, 2026
Merged
Conversation
Prior to this commit the application would copy all of the binaries in memory, use the first 12 bytes and copy the rest verbatim into the new output file.
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.
What does this PR do?
Prior to this change the application would copy all of the binaries in memory, use the first 12 bytes and copy the rest verbatim into the new output file.
How was this tested?
I built the binary from both the current
master(7ddd0e4) and this branch, applying a simple print out of the memory allocated for both.memory print-out patch
I then ran the built binaries against a simple "Hello, world!" Go binary built for amd64 and arm64 and fed them to both
makefatversions.Dummy binary
# Building the binaries GOARCH=amd64 go build -o world_amd64 ./hello.go GOARCH=arm64 go build -o world_arm64 ./hello.go$ ls -la world_* -rwxr-xr-x 1 the_mac staff 2569248 Apr 6 19:20 world_amd64 -rwxr-xr-x 1 the_mac staff 2492514 Apr 6 19:09 world_arm64What are the results of the changes
makefatnow doesn't scale its memory usage with binary input size.I've also tried it with a much larger Go binary (~25MB) and the new results are similar
Caveats
io.Copycall does not pass in a buffer so Go allocates a new 32kb one on each call