Repository navigation
Conversation
lqiu96
force-pushed
the
perf/bq-t1-15-lazy-jobs-get-pagination
branch
from
October 13, 2026 20:48
9c05bb2 to
4b1750c
Compare
lqiu96
force-pushed
the
perf/bq-t1-15-lazy-jobs-get-pagination
branch
from
October 13, 2026 21:14
4b1750c to
302b1a9
Compare
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
BigQueryImpl.queryRpc, when Page 1 completes with a non-nullpageToken,new QueryPageFetcher(...)executes a synchronous blockingthis.job = getJob(jobId)HTTP RPC inside its constructor before returning Page 1 to the caller. If the caller only inspects Page 1, thejobs.getRPC is wasted, and even for multi-page consumers it adds a full HTTP round-trip to time-to-first-row.QueryPageFetcheralso extendsjava.lang.Threadwithout ever starting the thread, registering an unstarted thread in the activeThreadGroupon every multi-page query.ConnectionImpl.processQueryResponseResults,getDestinationTable(jobId)executes a synchronous blockingjobs.getHTTP RPC even whenresults.getPageToken() == null(single-page fast-path queries) and submits an unnecessary background pagination task.ConnectionImpl.getSubsequentQueryResultsWithJobandtableDataList,Schema.fromPb(firstPage.getSchema())is parsed twice andgetQueryJobRpc(jobId)(jobs.getHTTP RPC) is invoked up to three times for the sameJobId.Changes
extends ThreadfromQueryPageFetcherand defergetJob(jobId)anddestinationTablelookup lazily intoQueryPageFetcher.getNextPage()injava-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java.getDestinationTable(jobId)andrunNextPageTaskAsyncbehindpageToken != nullinprocessQueryResponseResultsandtableDataListinjava-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java.Schema.fromPbingetSubsequentQueryResultsWithJoband cache the last resolvedJobperJobIdingetQueryJobRpcinjava-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java.java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ConnectionImplTest.javaverifying that single-pageprocessQueryResponseResultsskipsgetDestinationTableandgetQueryJobSkipExceptionTranslation.Expected Impact
Connectionfast-path query and before Page 1 return on every multi-pageBigQuery.query(...)call.jobs.getHTTP round-trips and 1 duplicateSchema.fromPbdeserialization onConnectionfallback and Read API queries.java.lang.Threadallocations andThreadGroup.addUnstarted()overhead inQueryPageFetcher.Verification
ConnectionImplTestandBigQueryImplTestvia Maven (174tests run,0failures).