Repository navigation
Conversation
…h direct ByteBuffer channel on Arrow batches
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary & Bottleneck
java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ArrowDeserializer.java(L165-L169)java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ArrowQueryResultImpl.java(L528-L530)java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java(L1115-L1118,L1139-L1142)ArrowDeserializer.loadArrowRowsandArrowQueryResultImpl.VectorBatchIterator.loadBatch(ByteString)wrappedbatch.getSerializedRecordBatch().newInput()inChannels.newChannel(...). In JDK'sChannels.ReadableByteChannelImpl,read(ByteBuffer dst)allocates abyte[8192]transfer buffer, acquiressynchronized (readLock)on every read, copies bytes fromInputStreamintobyte[8192], and then copies frombyte[8192]intodst.ConnectionImpl.ArrowRowReadercalledbatch.getSerializedRecordBatch().toByteArray()andarrowSchema.getSerializedSchema().toByteArray(), allocating a fullbyte[]copy of every serialized Arrow schema and record batch payload before wrapping it inByteArrayReadableSeekableByteChannel.Changes
ByteBufferchannel overByteString.asReadOnlyByteBuffer():ArrowDeserializer.newByteStringChannel(ByteString)returning a lightweight, unsynchronizedByteBufferReadableByteChannelthat copies slices directly frombyteString.asReadOnlyByteBuffer()into the targetByteBuffer.Channels.newChannelandtoByteArray()across Arrow readers:ArrowDeserializer.loadArrowRows,ArrowQueryResultImpl.VectorBatchIterator.loadBatch(ByteString), andConnectionImpl.ArrowRowReaderto useArrowDeserializer.newByteStringChannel(...).Expected Impact
byte[8192]bounce buffer allocation, double memory copy, andsynchronized (readLock)overhead per Arrow record batch inArrowDeserializerandArrowQueryResultImpl.byte[]array copies (toByteArray()) per Arrow record batch inConnectionImpl.ArrowRowReader.Verification
mvn test -pl java-bigquery/google-cloud-bigquery -Dtest=ArrowDeserializerTest,ArrowQueryResultTest,ArrowQueryPageFetcherTest,ConnectionImplTest(57 tests run, 0 failures).ArrowDeserializerTest.testNewByteStringChannelReadsIncrementalSlicesAndClosesto verify incremental slice reads, EOF semantics, and channel closure behavior.