damccorm opened a new pull request, #41059:
URL: https://github.com/apache/beam/pull/41059
### Description
Optimizes two per-element hot paths in `BigQueryWriteFn`
(`sdks/python/apache_beam/io/gcp/bigquery.py`):
1. **Fast-path row size estimation (`_fast_row_and_insert_id_size`):**
- `BigQueryWriteFn._check_row_size` previously called
`objsize.get_deep_size(row_and_insert_id)` on every incoming streaming insert
row. `objsize.get_deep_size` performs a general-purpose `gc.get_referents`
object graph traversal, costing ~170 µs per row.
- Adds `_fast_row_and_insert_id_size` to sum `sys.getsizeof` directly
when `row_and_insert_id` is a flat `(dict, insert_id)` tuple containing
primitive scalar keys and values (`str`, `int`, `float`, `bool`, `bytes`,
`None`), falling back to `get_deep_size` whenever nested containers or
non-primitive objects are present (**121.09x faster** on 50,000 8-field
streaming rows: `8.47s` -> `0.070s`).
2. **Skip redundant `parse_table_reference` in `BigQueryWriteFn.process`:**
- Skips resolving `self.schema` and calling
`bigquery_tools.parse_table_reference(destination)` on every element when
`self.create_disposition == BigQueryDisposition.CREATE_NEVER` or `destination`
is already present in `_KNOWN_TABLES` (matching the existing early-return guard
inside `_create_table_if_needed`).
### Testing
- Verified with `pytest sdks/python/apache_beam/io/gcp/bigquery_test.py
sdks/python/apache_beam/io/gcp/bigquery_tools_test.py`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]