damccorm opened a new pull request, #41209:
URL: https://github.com/apache/beam/pull/41209
### Description
Inlines all uses of `_OutputHandler._handle_tagged_output` in
`handle_process_outputs` and `handle_process_batch_outputs` and removes
`_handle_tagged_output` from `sdks/python/apache_beam/runners/common.py` and
`sdks/python/apache_beam/runners/common.pxd`:
- **Eliminate per-element 2-tuple packing and unpacking in
`_OutputHandler`:**
- Previously, `cdef inline tuple _handle_tagged_output(self, result)`
returned `(tag, result.value)` or `(None, result)`, causing Cython to allocate
and pack a 2-tuple (`PyTuple_Pack(2, ...)`) and immediately unpack it on every
yielded element or batch in both `handle_process_outputs` and
`handle_process_batch_outputs`.
- Inlining the `isinstance(result, TaggedOutput)` check directly in
`handle_process_outputs` and `handle_process_batch_outputs` assigns `tag` and
`result` directly to C local variables without allocating an intermediate
`tuple` on every output element.
### Benchmarks & Performance Impact
- **Microbenchmark Rerun:** [`bench_11_output_handler_batch_fastpath`
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/microbenchmarks.py#L203-L214)
(on branch
[`perf/py-benchmarks-suite`](https://github.com/damccorm/beam/tree/perf/py-benchmarks-suite))
— 600,000 yielded elements across 150,000 4-output
`_OutputHandler.handle_process_outputs` calls improved from **`72.50 ms` ->
`60.06 ms` (`1.21x` faster, `-17.2%`)** in compiled Cython (and **`48.71 ms` ->
`22.71 ms`, `2.15x` faster (`-53.4%`)** in the isolated tag-unwrapping loop).
- **Per-Change Attribution (Most to Least Impact):**
1. *Inlining `_handle_tagged_output` in `handle_process_outputs` (`-12.44
ms` full Cython / `-26.00 ms` isolated per 600,000 outputs):*
- Untagged outputs (150,000 calls x 4 elements): **`72.50 ms` -> `60.06
ms` (`1.21x` faster, `-17.2%`)** in full Cython `handle_process_outputs`.
- Mixed `TaggedOutput` + untagged outputs (150,000 calls x 4 elements):
**`90.02 ms` -> `77.47 ms` (`1.16x` faster, `-13.9%`)** in full Cython
`handle_process_outputs`.
- Isolated tag-unwrapping loop (600,000 outputs): **`48.71 ms` ->
`22.71 ms` (`2.15x` faster, `-53.4%`)**.
2. *Inlining `_handle_tagged_output` in `handle_process_batch_outputs`
(`-14.07 ms` per 100,000 4-element batches / `-19.43 ms` per 300,000 batch
outputs):*
- Element-yielding `handle_process_batch_outputs` (100,000 calls x 4
elements): **`78.44 ms` -> `64.37 ms` (`1.22x` faster, `-17.9%`)**.
- Batch-yielding `handle_process_batch_outputs` (300,000 calls):
**`706.14 ms` -> `686.71 ms` (`1.03x` faster, `-2.8%`)**.
- **End-to-End Cloud Dataflow Benchmark (`core_window_row_combine`):**
Included in [`run_core_window_row_combine_pipeline`
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/dataflow_e2e_benchmarks.py#L274-L302)
(3,000,000 generated events -> 9,000,000 sliding-windowed elements on a single
`n2-standard-4` worker), which improved end-to-end worker stage execution time
by **1.80x (`-44.5%`, `599.6s` -> `332.9s`)** and reduced total billable
Dataflow vCPU/Memory/PD usage by **`-26.1%` (`1,134` -> `838` vCPU-s)**.
### Testing
- Verified with `pytest sdks/python/apache_beam/runners/common_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]