[BUG] OpenReadAsync overprovisions buffer memory #47821
Labels
Client
This issue points to a problem in the data-plane of the library.
customer-reported
Issues that are reported by GitHub users external to the Azure organization.
needs-team-attention
Workflow: This issue needs attention from Azure service team or SDK team
question
The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Service Attention
Workflow: This issue is responsible by Azure service team.
Storage
Storage Service (Queues, Blobs, Files)
Library name and version
Azure.Storage.Blobs 12.23.0
Describe the bug
OpenReadAsync, if not provided a buffer size, defaults to 4MB. OpenReadAsync, as part of it's initialization, pulls the blob properties to fail fast if the blob does not exist. The blob length in these properties is used to initialize the
initialLenght
(note: misspelled) of the LazyLoadingReadonlyStream.There is an inefficiency here though. In the case where
allowModifications = false
andinitialLength < Constants.DefaultStreamingDownloadSize
, the stream will pre-initialize a buffer of 4MB (the default download size), but will never use the entire buffer. the math for the buffer initialization should beIn the case that a user requests a larger buffer (by specifying bufferSize in the read options), the client will honor that and create that buffer. Otherwise the default should allocate the buffer size wisely.
Expected behavior
LazyLoadingReadonlyStream
with a blob that does not allow modifications should create the smallest buffer necessaryActual behavior
LazyLoadingReadonlyStream
always creates a 4 MB buffer (if buffer size not specified)Reproduction Steps
Create 2KB blob
BlobOpenReadOptions options = new BlobOpenReadOptions(allowModifications: false)
var stream = await blobClient.OpenReadAsync(options: options)
stream._buffer is a byte array is 4MB in size.
Environment
No response
The text was updated successfully, but these errors were encountered: