-
Notifications
You must be signed in to change notification settings - Fork 464
fix(lib/store): initialise BufferedReadWriter with size #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modifies the NewBufferReadWriter constructor to accept a size parameter for pre-allocating the underlying buffer, improving memory efficiency for the in-memory cache.
Key changes:
- Added
size uint64parameter toNewBufferReadWriterto pre-allocate buffer capacity - Updated
addToMemoryCacheto pass the blob size toNewBufferReadWriter - Updated all test cases to pass
0as the size parameter
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/store/base/buffer_readwriter.go | Added size parameter to constructor and pre-allocates byte slice |
| lib/store/ca_store.go | Threaded size parameter through to addToMemoryCache and passed to NewBufferReadWriter |
| lib/store/base/buffer_readwriter_test.go | Updated all test instantiations to pass 0 for size parameter |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
880d7ec to
cc7845f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cc7845f to
ad6397c
Compare
ad6397c to
10129bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
What?
Initialise the
BufferedReadWriterfor writing blobs with the size of the blobWhy?
Currently, we initialise with 0 and it dynamically increase the size of the buffer which allocates a new buffer of the updated size and copies the existing to new one. This causes frequent copy and reallocs, causing latencies and higher cpu usage. The following profile shows the consequences
That's why it is better to allocate atleast the size of the blob beforehand and in case the size of actual blob is higher (which should be rare if the client stat is correctly implemented), buffer will adjust it automatically.
How?
use
client.Statprovided size to allocate the buffer of that size and pass it to theNewBufferedReadWriter.