-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
api, core: support zero copy into protobuf #8102
Merged
Merged
Changes from 47 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
9936df1
Add mark&reset methods and canUseByteBuffer&getByteBuffer methods to …
voidzcy aa93e1d
Default implementations.
voidzcy 454e224
Wire new methods for forwarder
voidzcy 3f47d5e
Support mark&reset and retrieving content via ByteBuffer for netty.
voidzcy b3c9974
Implementation for composite.
voidzcy 2ede525
Define interface for accessing readable content via ByteBuffers.
voidzcy 3dca312
Implement mark&reset for simple readable buffers.
voidzcy 6249353
Use HasByteBuffer interface for accesing input stream's backing ByteB…
voidzcy 29dce67
Eliminate the length argument for retrieving the ByteBuffer.
voidzcy 22ea6c3
Do no require netty buffer to be direct from API's perspective.
voidzcy 53e347c
Use Deque operations to avoid unncessary moves.
voidzcy 27801fe
Make a list of ByteBuffers up-front instead of a running iterator.
voidzcy eb71a68
Add getByteBufferSupported method for HasByteBuffer so that it can be…
voidzcy 5d3c657
It's not necessary to implement getByteBuffer for ByteReadbaleBufferW…
voidzcy 9fd8d3c
Add test coverage for mark&reset and getByteBuffer for generic ByteBu…
voidzcy e3afe50
Add test coverage for netty's special get NIO bytebuffer operation.
voidzcy e2fdd07
Skip test for operations not supported by okhttp.
voidzcy 033270b
Add test coverage for BufferInputStream with getByteBuffer operation.
voidzcy 0622d51
Add test using a known-length input stream with getByteBuffer operati…
voidzcy 0e8caee
Modify test method name.
voidzcy ba4e91b
Add test coverage for mark&reset and getByteBuffer for CompositeReada…
voidzcy 69618b2
Add getByteBuffer support for ByteReadableBufferWrapper.
voidzcy 437857d
Only pull ByteBuffers when message is large.
voidzcy 1363505
Run ByteBuffer codepath only in Java 9+.
voidzcy c46eb73
Slight improvement for avoiding array creation if not necessary.
voidzcy 7b4e070
Merge branch 'master' of github.com:grpc/grpc-java into impl/zero_cop…
voidzcy 772b3ba
Change ReadableBuffer#canUseByteBuffer to hasByteBuffer.
voidzcy b1c99e5
Removed unnecessary reset.
voidzcy 692076c
Simplify checking runtime java version.
voidzcy 10c13b8
Add ExperimentalApi annotation.
voidzcy f13c165
Rename ReadableBuffer#hasByteBuffer to getByteBufferSupported.
voidzcy 5c562b3
Merge branch 'master' of github.com:grpc/grpc-java into impl/zero_cop…
voidzcy 0f804b7
Revert changes for MessageMarshaller.
voidzcy ad64a1d
Add Retainable interface that allows taking over resource ownership a…
voidzcy aa902aa
Make BufferInputStream implements Retainable. Its close() method beco…
voidzcy 6cf0739
Remove no longer needed constructors.
voidzcy bfe1d7d
Change return type to be more specific.
voidzcy 4d90800
Restore optimizations for avoid allocating new buffer wrappers.
voidzcy d8d030a
Optimize by allocating rewindable buffer deque lazily.
voidzcy f1f1c95
Change to Detachable API, which makes the original InputStream behave…
voidzcy a2f3a9e
Change naming for getByteBufferSupported().
voidzcy 61c3447
Eliminate generics, use Object and casts instead.
voidzcy 15a0314
Return Detachable instead of Object.
voidzcy f8afce5
Hook BufferInputStream's markSupported() with underlying buffers.
voidzcy 2a6cbb6
Update Detachable interface definition, make it more specific to Inpu…
voidzcy e534f4a
Replace the internal buffer of BufferInputStream with an empty buffer…
voidzcy ad8940f
Add ExperimentalApi link.
voidzcy a6c1b13
Update Javadoc for Detachable.
voidzcy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2021 The gRPC Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.grpc; | ||
|
||
import java.io.InputStream; | ||
|
||
/** | ||
* A <i>Detachable</i> encapsulates some readable data source that can be detached and transferred | ||
* to an {@link InputStream}. The detached InputStream takes over the ownership of the | ||
* underlying data source. That's said, the detached InputStream is responsible for releasing its | ||
* resources after use. The detached InputStream preserves internal states of the underlying | ||
* data source. Data can be consumed through the detached InputStream as if being continually | ||
* consumed through the original instance. The original instance discards internal states of | ||
* detached data source and is no longer consumable as if the data source is exhausted. | ||
*/ | ||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/7387") | ||
public interface Detachable { | ||
|
||
/** | ||
* Detaches the underlying data source from this instance and transfers to an {@link | ||
* InputStream}. Detaching data from an already-detached instance gives an InputStream with | ||
* zero bytes of data. | ||
* | ||
*/ | ||
InputStream detach(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2020 The gRPC Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.grpc; | ||
|
||
import java.nio.ByteBuffer; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Extension to an {@link java.io.InputStream} whose content can be accessed as {@link | ||
* ByteBuffer}s. | ||
* | ||
* <p>This can be used for optimizing the case for the consumer of a {@link ByteBuffer}-backed | ||
* input stream supports efficient reading from {@link ByteBuffer}s directly. This turns the reader | ||
* interface from an {@link java.io.InputStream} to {@link ByteBuffer}s, without copying the | ||
* content to a byte array and read from it. | ||
*/ | ||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/7387") | ||
public interface HasByteBuffer { | ||
|
||
/** | ||
* Indicates whether or not {@link #getByteBuffer} operation is supported. | ||
*/ | ||
boolean byteBufferSupported(); | ||
|
||
/** | ||
* Gets a {@link ByteBuffer} containing some bytes of the content next to be read, or {@code | ||
* null} if has reached end of the content. The number of bytes contained in the returned buffer | ||
* is implementation specific. Calling this method does not change the position of the input | ||
* stream. The returned buffer's content should not be modified, but the position, limit, and | ||
* mark may be changed. Operations for changing the position, limit, and mark of the returned | ||
* buffer does not affect the position, limit, and mark of this input stream. This is an optional | ||
* method, so callers should first check {@link #byteBufferSupported}. | ||
* | ||
* @throws UnsupportedOperationException if this operation is not supported. | ||
*/ | ||
@Nullable | ||
ByteBuffer getByteBuffer(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we need to "throw the user a bone" here and give them a better hint why this exists. Let's say something about how the detached instance can outlive the original instance. And how it may be useful in a Marshaller to perform delayed deserialization or when combined with HasByteBuffer.
An really, let's rephrase the documentation to describe this as "An extension of InputStream." I think it will make it much more clear what is going on.
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.
Updated.