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

   ### Description
   
   Optimizes `AbstractComponentCoderImpl` in 
`sdks/python/apache_beam/coders/coder_impl.py` and 
`sdks/python/apache_beam/coders/coder_impl.pxd`:
   
   1. **Unroll 2-component (`KV`) fast path in `encode_to_stream` and 
`decode_from_stream`:**
      - Stores Cython attributes `_num_coders`, `_is_kv`, `_coder_0`, and 
`_coder_1` when `len(self._coder_impls) == 2` so 2-tuples (`KV` pairs) encode 
and decode directly without `range()` loop overhead or list comprehension + 
`tuple()` allocation on every element.
   
   ### Benchmarks & Performance Impact
   
   - **Isolated Microbenchmark Rerun (`upstream/master` vs `upstream/master` + 
this PR alone):** [`bench_17_component_coder_kv_fastpath` 
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/microbenchmarks.py#L287-L296)
 (on branch 
[`perf/py-benchmarks-suite`](https://github.com/damccorm/beam/tree/perf/py-benchmarks-suite))
 — 500,000 2-tuple (`KV`) encode + decode round-trips in `TupleCoderImpl` 
improved from **`220.40 ms` -> `124.94 ms` (`1.76x` faster, `-43.3%`, `-95.46 
ms`)** in compiled Cython.
   - **Per-Change Attribution (Most to Least Impact, 500,000 calls each in 
compiled Cython):**
     1. *Most impact (`60.7%` of stream savings, `-38.66 ms`):* 2-component 
`encode_to_stream` fast path (`_coder_0.encode_to_stream` / 
`_coder_1.encode_to_stream`) — **`74.72 ms` -> `36.06 ms` (`2.07x` faster, 
`-51.7%`)**.
     2. *Second (`39.3%` of stream savings, `-25.06 ms`):* 2-component 
`decode_from_stream` fast path (`(_coder_0.decode_from_stream, 
_coder_1.decode_from_stream)` without list comprehension + `tuple()`) — 
**`62.73 ms` -> `37.67 ms` (`1.67x` faster, `-39.9%`)**.
   - **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/coders/coders_test.py 
sdks/python/apache_beam/coders/fast_coders_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