Eliminate some allocations/copies around the blob cache #10647
Closed
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.
Summary:
Historically,
BlobFileReader
has returned the blob(s) read from the filein the
PinnableSlice
provided by the client. This interface waspreserved when caching was implemented for blobs, which meant that
the blob data was copied multiple times when caching was in use: first,
into the client-provided
PinnableSlice
(byBlobFileReader::SaveValue
),and then, into the object stored in the cache (by
BlobSource::PutBlobIntoCache
).The patch eliminates these copies and the related allocations by changing
BlobFileReader
so it returns its results in the form of heap-allocatedBlobContents
objects that can be directly inserted into the cache. The allocations backing
these
BlobContents
objects are made using the blob cache's allocator if theblobs are to be inserted into the cache (i.e. if a cache is configured and the
fill_cache
read option is set). Note: this PR focuses on the common case whenblobs are compressed; some further small optimizations are possible for uncompressed
blobs.
Test Plan:
make check