Repository navigation
perf(bigquery): [T2-2] stream Jackson tokens directly into FieldValueList without intermediate TableRow - #30
Open
lqiu96 wants to merge 1 commit into
Conversation
…List without intermediate TableRow
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
Even after PR #4 (
perf/bigquery-unwrap-cell-json) unwrapsTableCellJSON envelopes inHttpBigQueryRpc,parseTableRows(java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java:L2205-L2260) still allocates anew TableRow()(TableRow+GenericData'sRegularEnumSet+ArrayMap= 3 objects / 80 bytes per row), a transientArrayList<Object>per row inparseRowCells, a transientCollections.singletonMap("f", ...)+ArrayList<Object>perRECORDcell, and a transientArrayList<Object>perREPEATEDcell. Immediately afterward,BigQueryImpl.transformTableData(java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java:L2220-L2233) andConnectionImpl.getIterableFieldValueList(java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java:L826-L839) iterate overresult.getRows(), allocate a secondArrayList<FieldValue>+ twoIterators +ImmutableList.copyOfper row inFieldValueList.fromPb, and discard all intermediateTableRow,ArrayList<Object>, andSingletonMapwrappers.Changes
JsonParsertokens inHttpBigQueryRpc.parseTableRows/parseRowCells/parseCellFieldValue(java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java) directly into pre-sizedImmutableList<FieldValue>rows and nestedFieldValueListvalues without allocating intermediateTableRow,ArrayList<Object>, orSingletonMapinstances.StreamedTableRowListcarrier (16bytes per page) and expose@InternalApiHttpBigQueryRpc.extractFieldValueLists(Iterable<TableRow>, Schema, boolean)soBigQueryImpl.transformTableDataandConnectionImpl.getIterableFieldValueListwrap each pre-builtImmutableList<FieldValue>directly into aFieldValueListin zero-copyRECORDsub-field schemas andRANGEelement types only when present in the schema), whileStreamedTableRowList.get(int)lazily materializesTableRowif accessed by external callers.NULL_PRIMITIVEandNULL_PRIMITIVE_INT64_TIMESTAMPSflyweights inFieldValue.of(java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FieldValue.java) and short-circuitFieldValueList.withSchema(FieldList)(java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FieldValueList.java) when the schema is already attached.HttpBigQueryRpcTest(java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpcTest.java) verifyingHttpBigQueryRpc.extractFieldValueListsacross primitive, null, repeated, record, and repeated-record cells.Expected Impact
TableRow+RegularEnumSet+ArrayMap= ~80 bytes) per row, 2 intermediateArrayList+Object[]buffers per row, 2Iterators per row, intermediateSingletonMap("f", ...)andArrayList<Object>wrappers onRECORDandREPEATEDcells, and allFieldValueallocations onNULLcells.Verification
mvn test -pl java-bigquery/google-cloud-bigquery -Dtest=HttpBigQueryRpcTest,FieldValueTest,FieldValueListTest,BigQueryImplTest,ConnectionImplTest -Dclirr.skip=true -Denforcer.skip=true -Dcheckstyle.skip=true(267 tests passing).