feat(client): stream ParallelGet in-order to an io.Writer#360
Draft
worstell wants to merge 1 commit into
Draft
Conversation
4d97fb3 to
83e3e16
Compare
ParallelGet (and the DownloadGitSnapshot helper that wraps it) previously wrote chunks to an io.WriterAt, which requires a seekable destination (e.g. a temp file) and so prevents a consumer from overlapping the download with processing. They now fetch chunks in parallel but emit in-order bytes to a plain io.Writer via a bounded reorder buffer, letting a streaming consumer (e.g. a decompress/extract pipeline) run concurrently with the download. A concurrency-sized window caps fetched-but-unwritten chunks, and the reorder buffer is a ring of that many slots, bounding peak memory to O(concurrency * chunkSize) regardless of object size or consumer speed. A chunk whose body length differs from its requested range (short or overlong, e.g. a backend that ignored the range) is rejected rather than splicing or truncating. Revision safety (ETag pinning via If-Range), empty-object handling, range-ignore degrade, and the concurrency==1 shortcut are unchanged. The io.WriterAt variant is removed: no consumer benefited from scatter-writes, and the only use (download-to-temp-file then extract) is slower than streaming because it gives up download/extract overlap. Amp-Thread-ID: https://ampcode.com/threads/T-019ef6a9-a407-7389-bc43-001405e3ae9e Co-authored-by: Amp <amp@ampcode.com>
83e3e16 to
250ab5b
Compare
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.
ParallelGet— and theDownloadGitSnapshothelper that wraps it — previously wrote chunks to anio.WriterAt, which requires a seekable destination (e.g. a temp file) and so prevents a consumer from overlapping the download with processing. They now fetch chunks in parallel but emit in-order bytes to a plainio.Writervia a bounded reorder buffer, letting a streaming consumer (e.g. a decompress/extract pipeline) run concurrently with the download.A
concurrency-sized window caps fetched-but-unwritten chunks, and the reorder buffer is a ring of that many slots, bounding peak memory toO(concurrency * chunkSize)regardless of object size or consumer speed. A chunk whose body length differs from its requested range (short, or overlong from a backend that ignored the range) is rejected rather than spliced or truncated. Revision safety (ETag pinning viaIf-Range), empty-object handling, range-ignore degrade, and theconcurrency == 1shortcut are unchanged.The
io.WriterAtvariant is removed: no consumer benefited from scatter-writes, and the only use — download-to-temp-file then extract — is slower than streaming because it gives up download/extract overlap.*os.Filesatisfiesio.Writer, so the CLI caller is unaffected.Tests cover in-order reassembly, out-of-order completion, the single-worker/empty-object/range-ignore fallbacks, ETag-mismatch and overlong-chunk rejection, and error propagation, all under
-race.