Skip to content

Conversation

BenWhitehead
Copy link
Collaborator

"Child" change after #3278

Update BidiAppendableUnbufferedWritableByteChannel to only attempt to consume as many bytes as are available according to the stream -- this prevents over packing of segments we will for sure never be able to use.

With both this PR and the contents of #3278 our latency now looks like the following, where the v2.56.0 line represents the workload running using version 2.56.0 and v2.56.1+bw.2025_09_04_1715 represents the same workload bu using a version build from this PR.
image

@BenWhitehead BenWhitehead requested a review from a team as a code owner September 4, 2025 21:33
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: storage Issues related to the googleapis/java-storage API. labels Sep 4, 2025
BrandonY
BrandonY previously approved these changes Sep 4, 2025
for (int i = offset; i < length; i++) {
ByteBuffer buffer = bbs[i];
int remaining;
while ((remaining = buffer.remaining()) > 0) {
long overallRemaining = totalRemaining - consumedSoFar;
if (overallRemaining < blockSize && currentBlockPending == blockSize) {
break;
break outerloop;
Copy link

Choose a reason for hiding this comment

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

ooo, label break, those're rare!

}
if (numBytesConsumable <= 0) {
continue;
break outerloop;
Copy link

Choose a reason for hiding this comment

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

K...now I'm starting to worry a bit about cyclomatic complexity

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Prior to the appendable upload stuff we generally had a pretty firm bulkhead on the number of buffers that would be passed into these methods outside of tests. With the appendable addition we place less emphasis on early buffering in favor of passing things through wherever possible, so if multiple buffers are passed in here, logically the conditions would prevent consuming any bytes once a break from the while takes place, but by breaking the for as well we avoid the cycles performing work that isn't productive.

And, refactoring everything to nested method calls to allow early returns instead of break to label didn't seem worth it to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the follow up here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nothing from my perspective. There isn't a functional difference here between the label break and a separate method with early returns.

…r of bytes it should consume

Update BidiAppendableUnbufferedWritableByteChannel to only attempt to consume as many bytes as are available according to the stream -- this prevents over packing of segments we will for sure never be able to use.
@BenWhitehead BenWhitehead force-pushed the appendable/02/chunk-limit branch from 0bbbc42 to e07f2a4 Compare September 5, 2025 17:30
@BenWhitehead BenWhitehead merged commit 23584da into main Sep 9, 2025
25 checks passed
@BenWhitehead BenWhitehead deleted the appendable/02/chunk-limit branch September 9, 2025 17:25
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 googleapis/java-storage API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants