Skip to content

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

Merged
alvarowolfx merged 5 commits into
googleapis:mainfrom
fornwall:less-cloning
Aug 27, 2026
Merged

perf(bigquery): borrow schemas during REST row conversion#6503
alvarowolfx merged 5 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>

@alvarowolfx alvarowolfx 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.

Thanks for the improvements @fornwall

We usually try to avoid mut, so I added some minor style suggestions. But I can do it later since I'm doing some work semi-related to this.

Comment thread src/bigquery/src/query/row.rs
Comment thread src/bigquery/src/query/row.rs
@dbolduc

dbolduc commented Aug 25, 2026

Copy link
Copy Markdown
Member

/gcbrun

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.39%. Comparing base (4084332) to head (51fae86).
⚠️ Report is 31 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6503      +/-   ##
==========================================
- Coverage   96.39%   96.39%   -0.01%     
==========================================
  Files         301      301              
  Lines       84762    84752      -10     
==========================================
- Hits        81710    81699      -11     
- Misses       3052     3053       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Cover `convert_value`'s fallback arm, which is only reachable when a
cell value is neither null, string, object nor array.

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
@fornwall

Copy link
Copy Markdown
Contributor Author

1 line in your changes missing coverage

Just pushed a test hitting that.

@alvarowolfx

Copy link
Copy Markdown
Contributor

/gcbrun

@alvarowolfx
alvarowolfx merged commit a76f20a into googleapis:main Aug 27, 2026
42 of 43 checks passed
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.

3 participants