Skip to content
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

feat(storage): lazy allocation for upload buffer #11633

Conversation

coryan
Copy link
Contributor

@coryan coryan commented May 16, 2023

Allocating large upload buffers upfront can be slow if the application is going to send a small amount of data. Better grow the buffer as needed.


This change is Reviewable

Allocating large upload buffers upfront can be slow if the application
is going to send a small amount of data.  Better grow the buffer as
needed.
@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label May 16, 2023
@coryan coryan marked this pull request as ready for review May 16, 2023 21:01
@coryan coryan requested a review from a team as a code owner May 16, 2023 21:01
});
}
if (!last_status_.ok()) return traits_type::eof();
if (count + actual_size < max_buffer_size_) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q. Is there any reason to rewrite the test to avoid any possibility of overflow?

For example, if we know actual_size <= max_buffer_size_, then we might instead say...

  if (count < max_buffer_size_ - actual_size) {

Aside: Should the test be <=?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q. Is there any reason to rewrite the test to avoid any possibility of overflow?

For example, if we know actual_size <= max_buffer_size_, then we might instead say...

  if (count < max_buffer_size_ - actual_size) {

Thanks, done.

Aside: Should the test be <=?

I think it should be <: we want to flush the data when count == max_buffer_size - actual_size because at that point the buffer is large enough to justify the cost of said flush.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. It's not "is there space", but rather "is there space plus some". Thanks.

@coryan coryan enabled auto-merge (squash) May 16, 2023 21:38
@codecov
Copy link

codecov bot commented May 16, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (6d5e7f9) 93.78% compared to head (7ed53b7) 93.78%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11633   +/-   ##
=======================================
  Coverage   93.78%   93.78%           
=======================================
  Files        1824     1824           
  Lines      164394   164396    +2     
=======================================
+ Hits       154171   154184   +13     
+ Misses      10223    10212   -11     
Impacted Files Coverage Δ
...le/cloud/storage/internal/object_write_streambuf.h 100.00% <ø> (ø)
...e/cloud/storage/internal/object_write_streambuf.cc 100.00% <100.00%> (ø)

... and 8 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@coryan coryan merged commit 1db6acd into googleapis:main May 16, 2023
@coryan coryan deleted the feat-storage-reduce-initial-memory-allocation-for-uploads branch May 16, 2023 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants