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

   Note: this PR was auto-generated by tooling. Before moving it out of draft, 
the author has done a full review of the PR, specifically evaluating it on the 
following criteria:
   
   - The PR is an appropriate fix for the issue (e.g. we're not changing a test 
to avoid a bug)
   - The PR is a simple fix to the issue (e.g. we're not adding infra when we 
could just modify a test)
   - The PR is not covering for other problems (e.g. if we're bumping timeouts, 
it is not because we're covering for a performance problem)
   
   Full details of the methodology of generation and review can be found here - 
[Apache Beam Python SDK Performance PRs Methodology & Branches Impact 
Ranking](https://docs.google.com/document/d/1Edrmzp-qFHYs2j7dg9uFyV_jEMgq4QKt_JQDuuk-lmI/edit?usp=drivesdk)
   
   If you have concerns with the PR or with the underlying methodology used to 
generate this, please comment below - they will be addressed by the author not 
the tooling :)
   
   **Summary of changes:**
   
   Optimizes `RowCoderImpl` encoding and decoding in 
`sdks/python/apache_beam/coders/coder_impl.py` and `coder_impl.pxd`:
   
   1. **Fast-path `NamedTuple` construction on decode:**
      - Uses `tuple.__new__(self.constructor, args)` instead of unpacking 
`self.constructor(*args)`.
   2. **Fast-path `NamedTuple` and `operator.attrgetter` field extraction on 
encode:**
      - Uses `value` directly when `type(value) is self.constructor` (for 
`NamedTuple` instances) and a precompiled 
`operator.attrgetter(*self.field_names)` callable for `beam.Row` / `@dataclass` 
types instead of `[getattr(value, name) for name in self.field_names]`.
   
   **Dataflow benchmarks showing improvement:**
   
   - Before the change: 
[`2026-11-12_12_17_54-1512410260466266222`](https://console.cloud.google.com/dataflow/jobs/us-central1/2026-11-12_12_17_54-1512410260466266222?project=apache-beam-testing)
   - After the change: 
[`2026-11-12_12_17_54-1792881110204981549`](https://console.cloud.google.com/dataflow/jobs/us-central1/2026-11-12_12_17_54-1792881110204981549?project=apache-beam-testing)
   - Summary of perf improvement: In a single-worker (`n1-standard-8`, 
`--autoscaling_algorithm=NONE --num_workers=1 --max_num_workers=1`) Cloud 
Dataflow pipeline running `40,000,000` schema `PerfSchemaRow` elements · 
`Select(4 fields)` → `Reshuffle(num_buckets=64)` (`RowCoderImpl`), built-in 
transform stage execution time improved from **`3,421,381 ms` -> `3,355,310 ms` 
(`1.02x` faster, `-1.9%`)** (total single-worker job vCPU time: `4758s` -> 
`4618s`).
   
   **Additional benchmarks**
   
   - **Strict Single-PR Isolated Microbenchmark (`upstream/master` vs 
`upstream/master` + this PR alone):** [`bench_21_row_coder_impl_fastpath` 
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/microbenchmarks.py#L336-L349)
 (on branch 
[`perf/py-benchmarks-suite`](https://github.com/damccorm/beam/tree/perf/py-benchmarks-suite)):
     - **300,000 `RowCoderImpl.decode_from_stream` calls (`NamedTuple`):** 
Improved from **`339.94 ms` -> `313.77 ms` (`1.08x` faster, `-7.7%`, `-26.17 
ms`)** in compiled Cython (and **`1.49x` faster** in pure Python).
     - **300,000 `RowCoderImpl` encode + decode round-trips (`bench_21`):** 
Improved from **`347.39 ms` -> `332.27 ms` (`1.05x` faster, `-4.4%`, `-15.12 
ms`)** locally in Cython (**`3.10x` faster** in pure Python).
   - **On-Worker Cloud Dataflow `n2-standard-4` Benchmark 
(`p28_ms:03_row_coder_impl_300k` & `subbench_ms:02_row_coder_roundtrip_ms`):** 
On a Cloud Dataflow `n2-standard-4` worker, 300,000 `RowCoderImpl` round-trips 
improved from **`724 ms` -> `566 ms` (`1.28x` faster, `-21.8%`)**, and 
`subbench_ms:02` in `core_window_row_combine` improved from **`620 ms` -> `485 
ms` (`1.28x` faster)**.
   - **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)
 (`3M` events -> `9M` sliding-windowed elements on `n2-standard-4`), which 
improved end-to-end worker stage execution time by **1.80x (`-44.5%`, `599.6s` 
-> `332.9s`)**.
   
   ### Testing
   - Verified with `pytest sdks/python/apache_beam/coders/row_coder_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