Repository navigation
blob/gcsblob: size the upload buffer to the blob in WriteAll - #3858
Open
iamabhilaksh wants to merge 2 commits into
Open
iamabhilaksh wants to merge 2 commits into
iamabhilaksh wants to merge 2 commits into
Conversation
When BufferSize is 0, each storage.Writer allocated a 16 MiB buffer, even for tiny writes. WriteAll now passes the blob size to the driver as a hint, and gcsblob uses it to cap the buffer.
…ithout ContentType newWriter adds a stack frame, so use runtime.Caller(2) like newRangeReader.
iamabhilaksh
marked this pull request as ready for review
November 23, 2026 08:32
This branch has not been deployed
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.
Problem
When
BufferSizeis not set, gcsblob gives every upload a 16 MiB memory buffer, even for a 1 KiB blob. Many small writes at once can use hundreds of MB: 16 writes of 10 KiB grew memory by about 269 MB on real GCS.WriteAllknows the blob's size but didn't pass it on. Details in #3857.Fixes #3857
Change
WriteAllnow tells the driver how big the blob is, through a newSizeHintfield indriver.WriterOptions.NewWriternow goes through a small helper, so the "Writer was never closed" log usesruntime.Caller(2)to keep pointing at the caller's code, like the Reader does.TestBufferSizechecks the buffer size for different hints.TestWriteAllChunkSizechecks the buffer gcsblob gets fromWriteAll(small, empty, noContentType, 16 MiB, withBufferSize) and fromNewWriter.Impact and risk
WriteAllcalls on GCS use about 98% less memory.BufferSizeis set, forNewWriterandUpload, for blobs of 16 MiB or more, or for other drivers.Testing
ContentTypecases inTestWriteAllChunkSizefail on master (got ChunkSize 16777216) and pass with this change.go test -race,go vet,gofmtand golangci-lint v2.14.0 pass on go1.27.3 and go1.26.10.