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

   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 `WindowedValueCoderImpl.get_estimated_size_and_observables` and 
`_from_normal_time` in `sdks/python/apache_beam/coders/coder_impl.py` and 
`coder_impl.pxd`:
   
   1. **Avoid `value.timestamp` object materialization during size estimation:**
      - `TimestampCoderImpl.estimate_size` always returns 8 bytes (big-endian 
uint64), whereas accessing `value.timestamp` on a freshly created 
`WindowedValue` (constructed via `windowed_value.create(val, timestamp_micros, 
windows)`) lazily allocated a `Timestamp` object on every size check.
      - Typing `wv=windowed_value.WindowedValue` in `@cython.locals` and adding 
`8` directly eliminates `Timestamp` allocation and 
`self._timestamp_coder.estimate_size` dispatch.
   2. **Precompute `MIN_TIMESTAMP_millis` and `MAX_TIMESTAMP_millis` as 
module-level `cdef int64_t` constants in `_from_normal_time`.**
   
   **Dataflow benchmarks showing improvement:**
   
   - Before the change: 
[`2026-11-12_12_17_52-5440785737820341136`](https://console.cloud.google.com/dataflow/jobs/us-central1/2026-11-12_12_17_52-5440785737820341136?project=apache-beam-testing)
   - After the change: 
[`2026-11-12_12_17_54-17880020816897816483`](https://console.cloud.google.com/dataflow/jobs/us-central1/2026-11-12_12_17_54-17880020816897816483?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` windowed KV · 
`WindowInto(FixedWindows(10))` → `Reshuffle(num_buckets=64)` 
(`WindowedValueCoderImpl`), built-in transform stage execution time improved 
from **`1,214,600 ms` -> `1,119,991 ms` (`1.08x` faster, `-7.8%`)** (total 
single-worker job vCPU time: `7301s` -> `7091s`).
   
   **Additional benchmarks**
   
   - **Strict Single-PR Isolated Microbenchmark (`upstream/master` vs 
`upstream/master` + this PR alone):** 
[`bench_19_windowed_value_coder_impl_size` 
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/microbenchmarks.py#L314-L321)
 (on branch 
[`perf/py-benchmarks-suite`](https://github.com/damccorm/beam/tree/perf/py-benchmarks-suite)):
     - **Freshly created `WindowedValue`s (`_timestamp_object is None`, 200,000 
calls):** Improved from **`392.14 ms` -> `101.96 ms` (`3.85x` faster, `-74.0%`, 
`-290.18 ms`)** in compiled Cython.
     - **Reused/warm `WindowedValue` (`bench_19`, 500,000 calls):** Improved 
from **`770.48 ms` -> `700.61 ms` (`1.10x` faster, `-9.1%`, `-69.87 ms`)** in 
compiled Cython.
   - **On-Worker Cloud Dataflow `n2-standard-4` Benchmark 
(`p28_ms:01b_wv_coder_size_fresh_200k` & 
`p28_ms:01_wv_coder_size_warm_500k`):** On a Cloud Dataflow `n2-standard-4` 
worker, 200,000 fresh `WindowedValue` size estimations (including 
`windowed_value.create`) improved from **`774 ms` -> `479 ms` (`1.62x` faster, 
`-38.1%`)**, and 500,000 warm calls improved from **`1,089 ms` -> `971 ms` 
(`1.12x` faster, `-10.8%`)**.
   - **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/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