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

   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 `_PartialGroupByKeyCombiningValues.process` (`combiners.py`) and 
`ListBatchConverter.combine_batches` (`typehints/batch.py`):
   
   1. **Replace quadratic `sum(batches, [])` in 
`ListBatchConverter.combine_batches` with 
`list(itertools.chain.from_iterable(batches))`.**
   2. **Reuse `self._cached_windowed_side_inputs[window]` in 
`_PartialGroupByKeyCombiningValues.process` instead of calling 
`_unpack_side_inputs(side_inputs)` on every input element:**
      - Previously, `_PartialGroupByKeyCombiningValues.process` populated 
`self._cached_windowed_side_inputs[window]` at the end of `process()` (for 
`finish_bundle()`), but still unconditionally called 
`_unpack_side_inputs(side_inputs)` on every single element!
   
   **Dataflow benchmarks showing improvement:**
   
   - Before the change: 
[`2026-11-12_12_18_08-11254241421410634130`](https://console.cloud.google.com/dataflow/jobs/us-central1/2026-11-12_12_18_08-11254241421410634130?project=apache-beam-testing)
   - After the change: 
[`2026-11-12_12_18_07-3349445483990798491`](https://console.cloud.google.com/dataflow/jobs/us-central1/2026-11-12_12_18_07-3349445483990798491?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 `30,000,000` elements (`50,000` keys) · `Distinct` → 
`CombinePerKey(AsSingleton, AsList, AsIter, AsDict)`, built-in transform stage 
execution time improved from **`899,082 ms` -> `785,763 ms` (`1.14x` faster, 
`-12.6%`)** (total single-worker job vCPU time: `2003s` -> `2178s`).
   
   **Additional benchmarks**
   
   - **Strict Single-PR Isolated Microbenchmark (`upstream/master` vs 
`upstream/master` + this PR alone):** 
[`bench_37_pgbk_combining_values_side_inputs` 
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/microbenchmarks.py#L523-L530)
 (on branch 
[`perf/py-benchmarks-suite`](https://github.com/damccorm/beam/tree/perf/py-benchmarks-suite))
 — 10,000 `ListBatchConverter.combine_batches` calls on 200-batch lists 
improved from **`938.91 ms` -> `181.53 ms` (`5.17x` faster, `-80.7%`, `-757.38 
ms`)** in strict isolation.
   - **On-Worker Cloud Dataflow `n2-standard-4` Benchmark 
(`p28_ms:18_pgbk_combine_batches_10k`):** On a Cloud Dataflow `n2-standard-4` 
worker, 10,000 `ListBatchConverter.combine_batches` calls improved from 
**`1,327 ms` -> `213 ms` (`6.23x` faster, `-83.9%`)**.
   - **End-to-End Cloud Dataflow Benchmark (`s8-loadtest` & `s6-ml-inf`):** 
Included in `suite8_loadtest_gbk_cogbk_sideinput_pardo` (windowed `AsDict` 
side-input combining, **1.20x faster: `24.2s` -> `20.2s`**) and 
`suite6_ml_runinference` (**2.33x faster: `99.1s` -> `42.6s`**).
   
   ### Testing
   - Verified with `pytest sdks/python/apache_beam/transforms/combiners_test.py 
sdks/python/apache_beam/typehints/batch_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