damccorm opened a new pull request, #41161:
URL: https://github.com/apache/beam/pull/41161

   ### Description
   
   Optimizes `PerWindowInvoker._invoke_process_per_window` kwargs handling and 
`_OutputHandler.handle_process_outputs` in 
`sdks/python/apache_beam/runners/common.py`:
   
   1. **Avoid empty `kwargs_for_process` dict allocation and `**kwargs` 
unpacking:**
      - Calls `self.process_method(*args_for_process)` directly when 
`kwargs_for_process` is empty/None instead of `kwargs_for_process = 
kwargs_for_process or {}` and unpacking `**kwargs_for_process` on every 
invocation.
   2. **Fast-path `results is None` and inline `TaggedOutput` check in 
`_OutputHandler.handle_process_outputs`:**
      - Returns early when `results is None` (after updating 
`per_element_output_counter` if enabled) instead of allocating an empty list 
`results = []`, and inlines `isinstance(result, TaggedOutput)` to avoid calling 
`self._handle_tagged_output(result)` and allocating a `(tag, result)` tuple on 
every output element.
   
   ### Benchmarks & Performance Impact
   
   - **Microbenchmark:** [`bench_10_per_window_invoker_kwargs_and_output` 
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/microbenchmarks.py#L198-L200)
 (on branch 
[`perf/py-benchmarks-suite`](https://github.com/damccorm/beam/tree/perf/py-benchmarks-suite))
 — `_OutputHandler.handle_process_outputs` and `PerWindowInvoker` dispatch 
improved by **1.25x–1.65x** across single- and multi-window outputs.
   - **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]

Reply via email to