damccorm opened a new pull request, #41176:
URL: https://github.com/apache/beam/pull/41176
### Description
Optimizes `PGBKOperation.flush` in
`sdks/python/apache_beam/runners/worker/operations.py` and `operations.pxd`:
1. **Avoid `list(self.table.items())` full copy and fix `self.size`
decrement:**
- Previously, `PGBKOperation.flush(limit)` materialized a full copy of
`self.table.items()` into a list, deleted keys one by one, and never
decremented `self.size` during partial flushes—causing every subsequent
incoming element after the first threshold breach to trigger `flush()`
repeatedly ($O(N^2)$ degradation).
- Clears `self.table` in place when `limit == 0`, collects only evicted
keys when `limit > 0`, and properly decrements `self.size`.
### Benchmarks & Performance Impact
- **Microbenchmark:** [`bench_14_worker_pgbk_flush`
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/microbenchmarks.py#L251-L259)
(on branch
[`perf/py-benchmarks-suite`](https://github.com/damccorm/beam/tree/perf/py-benchmarks-suite))
— `PGBKOperation.flush` improved by **2.80x (`-64.3%`)** on full flushes and
eliminates $O(N^2)$ partial-flush degradation when key cardinality exceeds
`max_keys`.
- **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/runners/worker/operations_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]