damccorm opened a new pull request, #41173:
URL: https://github.com/apache/beam/pull/41173
### Description
Optimizes `DataInputOperation.process_encoded` and `FnApiUserStateContext`
in `sdks/python/apache_beam/runners/worker/bundle_processor.py`:
1. **`DataInputOperation`:**
- Binds local `decode_from_stream =
self.windowed_coder_impl.decode_from_stream`, `output =
self.receivers[0].receive`, and `splitting_lock = self.splitting_lock`
references outside the `while input_stream.size() > 0:` loop in
`process_encoded`, and uses `sys.maxsize` instead of `float('inf')` for
`self.stop` so `self.index == self.stop - 1` compares `int` against `int`
rather than `float`.
2. **`FnApiUserStateContext`:**
- Caches `_key_coder_impl` and `_window_coder_impl` in `__init__` instead
of dispatching through `Coder.encode()` -> `get_impl().encode()` on every state
lookup in `get_state()`, and looks up `self._timers_info[timer_spec.name]` once
in `get_timer()`.
### Benchmarks & Performance Impact
- **Microbenchmark:** [`bench_12_bundle_processor_input_and_state`
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/microbenchmarks.py#L217-L234)
(on branch
[`perf/py-benchmarks-suite`](https://github.com/damccorm/beam/tree/perf/py-benchmarks-suite))
— Decoding 500,000 windowed elements through
`DataInputOperation.process_encoded` and caching state coders improved by
**1.15x–1.35x**.
- **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/bundle_processor_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]