Skip to content

perf(bigquery): borrow schemas during REST row conversion - #6503

Open
fornwall wants to merge 3 commits into
googleapis:mainfrom
fornwall:less-cloning
Open

perf(bigquery): borrow schemas during REST row conversion#6503
fornwall wants to merge 3 commits into
googleapis:mainfrom
fornwall:less-cloning

Conversation

@fornwall

Copy link
Copy Markdown
Contributor

Row conversion cloned table field schemas and allocated temporary schema wrappers for every cell, even though conversion only reads schema metadata.

Pass borrowed field slices through the recursive conversion instead, which removes a deep TableFieldSchema clone, an Arc, and a TableSchema allocation per cell for scalar, nested and repeated values.

Also reserve the cell vector up front, now that the column count is known before the loop runs.

Row conversion cloned table field schemas and allocated temporary
schema wrappers for every cell, even though conversion only reads
schema metadata. Pass borrowed field slices through the recursive
conversion instead, which removes a deep `TableFieldSchema` clone, an
`Arc`, and a `TableSchema` allocation per cell for scalar, nested and
repeated values.

Also reserve the cell vector up front, now that the column count is
known before the loop runs.

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
@fornwall
fornwall requested a review from a team as a code owner August 21, 2026 22:34
@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the BigQuery API. label Aug 21, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 refactors the BigQuery row conversion logic to optimize allocations and simplify the code by passing TableFieldSchema directly to conversion functions instead of reconstructing intermediate Schema objects. The review feedback suggests a further optimization in convert_repeated to pre-allocate the values list using ListValue::with_capacity since the input size is known beforehand.

Comment thread src/bigquery/src/query/row.rs Outdated
Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
`convert_row` and `convert_repeated` own the cell vector they receive,
so they can map it in place with `Value::take()` instead of building a
second vector alongside it. This drops one `Vec` allocation per row,
per repeated field and per nested record, and subsumes the capacity
reservation added earlier.

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the BigQuery API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant