-
Notifications
You must be signed in to change notification settings - Fork 4.4k
[9.0.0] Avoid materialization of VirtualActionInputs during uploads #28278
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
By using a `Piped{Input,Output}Stream` pair backed by a virtual thread, uploads of `VirtualActionInput` no longer have to materialize the full input in memory and thus require less peak heap.
Closes bazelbuild#28259.
PiperOrigin-RevId: 855713407
Change-Id: I3e382fd4da2fe0f2899d5b00d19d718ddce1a54c
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.
Code Review
This pull request introduces a significant improvement by avoiding the materialization of VirtualActionInputs in memory during uploads, utilizing PipedInputStream and PipedOutputStream backed by virtual threads. This change effectively reduces peak heap memory usage, which is crucial for performance and stability, especially with large virtual inputs. The changes are well-aligned with the goal of optimizing memory footprint. However, there are a couple of areas that need attention regarding error handling and API documentation to ensure correctness and clarity.
| throw new IllegalStateException( | ||
| "writeTo is not expected to throw as pipedOut doesn't", e); | ||
| } |
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.
The IllegalStateException message here states that writeTo is "not expected to throw as pipedOut doesn't". However, PipedOutputStream.write can indeed throw an IOException if the pipe is broken or closed (e.g., if the reading thread dies unexpectedly). Wrapping this in an IllegalStateException with a misleading message could obscure the root cause of potential issues. It's better to either handle the IOException more gracefully or at least provide a more accurate error message that acknowledges the possibility of an IOException from the underlying stream.
| throw new IllegalStateException( | |
| "writeTo is not expected to throw as pipedOut doesn't", e); | |
| } | |
| throw new IllegalStateException( | |
| "Failed to write virtual action input to piped output stream", e); |
| @@ -100,7 +99,7 @@ ListenableFuture<Void> downloadBlob( | |||
| * as late as possible and close the blob as soon as they are done with it. | |||
| */ | |||
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.
The Javadoc states that "consumers should call {@link #get} as late as possible and close the blob as soon as they are done with it." However, the Blob interface no longer extends Closeable. This makes the documentation misleading, as there is no close() method to call directly on the Blob interface. The documentation should be updated to reflect this change, or if Blob implementations are still expected to be closed, an alternative mechanism should be documented.
* as late as possible. Implementations are responsible for managing the lifecycle of any underlying resources.|
Gemini findings are interesting, let's not cherry-pick this into 9.0.0 (but perhaps into 9.1.0). |
By using a
Piped{Input,Output}Streampair backed by a virtual thread, uploads ofVirtualActionInputno longer have to materialize the full input in memory and thus require less peak heap.Closes #28259.
PiperOrigin-RevId: 855713407
Change-Id: I3e382fd4da2fe0f2899d5b00d19d718ddce1a54c
Commit 92dad2c