Repository navigation
core: copy zip entries through File.extract's pooled buffer - #14949
Merged
Merged
Conversation
grouville
self-requested a review
October 29, 2026 06:24
grouville
approved these changes
Oct 29, 2026
io.CopyBuffer hands the copy to the destination's ReadFrom when it has one, and *os.File's falls back to io.Copy for a zip entry, which allocates a new 32 KiB buffer per file: the pooled buffer was never used. In a cold first build of dagger's CLI that was 1.6 GiB of the engine's 8.9 GiB allocated. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
sipsma/file-extract-zip-copy-buffer
branch
from
October 29, 2026 06:26
40b8c1c to
8b1b6a6
Compare
sipsma
added a commit
that referenced
this pull request
Oct 30, 2026
poolsCopy passed the opened *os.File to io.CopyBuffer, which hands the copy to the file's WriteTo when it has one. A hash has no fast path to take, so WriteTo fell back to a copy with its own new buffer for every file, and the pooled 32 KiB buffer went unused. Hiding WriteTo makes CopyBuffer use the pooled buffer, as #14949 did for ReadFrom in zip extraction. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
added a commit
that referenced
this pull request
Oct 30, 2026
poolsCopy passed the opened *os.File to io.CopyBuffer, which hands the copy to the file's WriteTo when it has one. A hash has no fast path to take, so WriteTo fell back to a copy with its own new buffer for every file, and the pooled 32 KiB buffer went unused. Hiding WriteTo makes CopyBuffer use the pooled buffer, as #14949 did for ReadFrom in zip extraction. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
added a commit
that referenced
this pull request
Oct 31, 2026
poolsCopy passed the opened *os.File to io.CopyBuffer, which hands the copy to the file's WriteTo when it has one. A hash has no fast path to take, so WriteTo fell back to a copy with its own new buffer for every file, and the pooled 32 KiB buffer went unused. Hiding WriteTo makes CopyBuffer use the pooled buffer, as #14949 did for ReadFrom in zip extraction. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
added a commit
that referenced
this pull request
Nov 2, 2026
poolsCopy passed the opened *os.File to io.CopyBuffer, which hands the copy to the file's WriteTo when it has one. A hash has no fast path to take, so WriteTo fell back to a copy with its own new buffer for every file, and the pooled 32 KiB buffer went unused. Hiding WriteTo makes CopyBuffer use the pooled buffer, as #14949 did for ReadFrom in zip extraction. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
added a commit
that referenced
this pull request
Nov 2, 2026
poolsCopy passed the opened *os.File to io.CopyBuffer, which hands the copy to the file's WriteTo when it has one. A hash has no fast path to take, so WriteTo fell back to a copy with its own new buffer for every file, and the pooled 32 KiB buffer went unused. Hiding WriteTo makes CopyBuffer use the pooled buffer, as #14949 did for ReadFrom in zip extraction. Signed-off-by: Erik Sipsma <[email protected]>
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.
File.extractwrites each zip entry withio.CopyBufferand a pooled 128 KiB buffer, but that buffer was never used. The destination is an*os.File, soio.CopyBufferhands the copy toFile.ReadFrom. That has no fast path from a zip entry, so it falls back toio.Copy, which allocates a new 32 KiB buffer for every file extracted.This passes only the file's
io.Writer, asinternal/fsutil/send.goalready does on the reader side, so the pooled buffer is used. Nothing else changes: the copy loop, short-write detection and error handling are the same. Chunks are 128 KiB instead of 32 KiB.Measured on a cold first build of dagger's CLI with the per-package Go build (github.com/dagger/go), which extracts every module it downloads with
File.extract. A 16-core arm64 machine, fresh engines, 6 rounds, each paired against the same engine without this change:The existing
TestExtract*unit tests in./corecover what extraction produces, and they pass.