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

   ### Description
   
   Optimizes `_IntervalWindowBase.__eq__` and `__hash__` in 
`sdks/python/apache_beam/utils/windowed_value.py` and `windowed_value.pxd`:
   
   1. **Exact-type fast path in `_IntervalWindowBase.__eq__`:**
      - Checks `type(self) is type(other)` first to compare `_start_micros == 
other._start_micros and _end_micros == other._end_micros` directly.
   2. **Avoid tuple allocation in `_IntervalWindowBase.__hash__`:**
      - Replaces `hash((self._start_micros, self._end_micros))` with direct 
integer bit-mixing without allocating a 2-tuple per hash lookup.
   
   ### Benchmarks & Performance Impact
   
   - **Microbenchmark:** [`bench_04_interval_window_eq_hash` 
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/microbenchmarks.py#L107-L117)
 (on branch 
[`perf/py-benchmarks-suite`](https://github.com/damccorm/beam/tree/perf/py-benchmarks-suite))
 — 1,000,000 `IntervalWindow` equality and `hash()` calls improved by **6.27x 
(`-84.1%`)** on `__eq__` and **3.04x (`-67.1%`)** on `__hash__`.
   - **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/transforms/window_test.py 
sdks/python/apache_beam/utils/windowed_value_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