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

   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 `ApproximateQuantilesCombineFn.add_input` and `_QuantileState` in 
`sdks/python/apache_beam/transforms/stats.py`:
   
   1. **Append directly to `quantile_state.unbuffered_elements` in 
`ApproximateQuantilesCombineFn.add_input` and only call `_add_unbuffered` when 
`len(unbuffered_elements) >= buffer_size`:**
      - Avoids allocating a 1-element list `[element]` and calling 
`add_unbuffered` / `_collapse_if_needed` on every single input element when the 
unbuffered list has not yet reached `buffer_size`.
   
   **Dataflow benchmarks showing improvement:**
   
   - Before the change: 
[`2026-11-12_12_18_05-5250338823185786759`](https://console.cloud.google.com/dataflow/jobs/us-central1/2026-11-12_12_18_05-5250338823185786759?project=apache-beam-testing)
   - After the change: 
[`2026-11-12_12_18_07-10427076549794849922`](https://console.cloud.google.com/dataflow/jobs/us-central1/2026-11-12_12_18_07-10427076549794849922?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` KV (`1,024` keys) · 
`ApproximateQuantiles.PerKey(10)`, built-in transform stage execution time 
improved from **`208,474 ms` -> `188,581 ms` (`1.11x` faster, `-9.5%`)** (total 
single-worker job vCPU time: `1233s` -> `1290s`).
   
   **Additional benchmarks**
   
   - **Strict Single-PR Isolated Microbenchmark (`upstream/master` vs 
`upstream/master` + this PR alone):** [`bench_39_approx_quantiles_fastpath` 
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/microbenchmarks.py#L543-L551)
 (on branch 
[`perf/py-benchmarks-suite`](https://github.com/damccorm/beam/tree/perf/py-benchmarks-suite))
 — 400,000 `ApproximateQuantilesCombineFn.add_input` calls improved from 
**`105.57 ms` -> `91.97 ms` (`1.15x` faster, `-12.9%`, `-13.60 ms`)** in strict 
isolation.
   - **On-Worker Cloud Dataflow `n2-standard-4` Benchmark 
(`p28_ms:20_approx_quantiles_400k`):** On a Cloud Dataflow `n2-standard-4` 
worker, 400,000 `ApproximateQuantilesCombineFn.add_input` calls improved from 
**`200 ms` -> `156 ms` (`1.28x` faster, `-22.0%`)**.
   - **End-to-End Cloud Dataflow Benchmark (`io_coders_transforms` & 
`s4-avro-tfrec`):** Included in [`run_io_coders_transforms_pipeline` 
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/dataflow_e2e_benchmarks.py#L305-L335)
 (**1.48x faster: `49.2s` -> `33.3s`**) and `suite4_avro_tfrecord_mltransform` 
(**1.23x faster: `108.8s` -> `88.7s`**).
   
   ### Testing
   - Verified with `pytest sdks/python/apache_beam/transforms/stats_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