Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sambhav-jain-16
Copy link
Collaborator

@sambhav-jain-16 sambhav-jain-16 commented Nov 7, 2025

What?

Initialise the BufferedReadWriter for writing blobs with the size of the blob

Why?

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

Screenshot 2025-11-07 at 22 13 29

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.Stat provided size to allocate the buffer of that size and pass it to the NewBufferedReadWriter.

Copilot AI review requested due to automatic review settings November 7, 2025 21:15
Copy link
Contributor

Copilot AI left a 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 uint64 parameter to NewBufferReadWriter to pre-allocate buffer capacity
  • Updated addToMemoryCache to pass the blob size to NewBufferReadWriter
  • Updated all test cases to pass 0 as 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.

Copy link
Contributor

Copilot AI left a 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.

@sambhav-jain-16
Copy link
Collaborator Author

sambhav-jain-16 commented Nov 10, 2025

CPU usage graph before
Screenshot 2025-11-10 at 10 29 01

CPU usage graph after

Screenshot 2025-11-10 at 10 29 28

Copilot AI review requested due to automatic review settings November 10, 2025 10:19
Copy link
Contributor

Copilot AI left a 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.

@sambhav-jain-16 sambhav-jain-16 merged commit 65dd0c9 into uber:master Nov 10, 2025
10 checks passed
@sambhav-jain-16 sambhav-jain-16 deleted the size_buffer branch November 10, 2025 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants