damccorm opened a new pull request, #41275: URL: https://github.com/apache/beam/pull/41275
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 `MetricsContainer._get_typed_metric_name` (`get_counter`, `get_distribution`, `get_gauge`, `get_string_set`, `get_bounded_trie`) in `sdks/python/apache_beam/metrics/execution.py`: 1. **Cache `_TypedMetricName(cell_type, metric_name)` on `metric_name._typed_metric_names` instead of allocating a new `_TypedMetricName` wrapper object on every metric cell lookup.** **Dataflow benchmarks showing improvement:** - Before the change: [`2026-11-12_13_27_21-10243732593640248076`](https://console.cloud.google.com/dataflow/jobs/us-central1/2026-11-12_13_27_21-10243732593640248076?project=apache-beam-testing) - After the change: [`2026-11-12_13_27_21-17180255097007214814`](https://console.cloud.google.com/dataflow/jobs/us-central1/2026-11-12_13_27_21-17180255097007214814?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` elements (`240,000,000` metric lookups) · 2× `ParDo(MetricsContainer.get_counter)`, built-in transform stage execution time improved from **`2,297,401 ms` -> `1,543,987 ms` (`1.49x` faster, `-32.8%`)** (total single-worker job vCPU time: `3353s` -> `2611s`). **Additional benchmarks** - **Strict Single-PR Isolated Microbenchmark (`upstream/master` vs `upstream/master` + this PR alone):** [`bench_31_metrics_container_typed_name_cache` (`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/microbenchmarks.py#L453-L463) (on branch [`perf/py-benchmarks-suite`](https://github.com/damccorm/beam/tree/perf/py-benchmarks-suite)) — 640,000 `MetricsContainer.get_counter(mn).inc()` calls improved from **`377.38 ms` -> `140.37 ms` (`2.69x` faster, `-62.8%`, `-237.01 ms`)** in strict isolation. - **On-Worker Cloud Dataflow `n2-standard-4` Benchmark (`p28_ms:13_metrics_container_typed_name_640k` & `subbench_ms:03_metrics_container_lookup_ms`):** On a Cloud Dataflow `n2-standard-4` worker, 640,000 `MetricsContainer.get_counter(mn)` lookups improved from **`567 ms` -> `216 ms` (`2.63x` faster, `-61.9%`)**, and 512,000 `get_counter(MetricName).inc()` updates in `WorkerSubsystemBenchDoFn` improved from **`517 ms` -> `180 ms` (`2.87x` faster)**. - **End-to-End Cloud Dataflow Benchmark (`core_window_row_combine` & `s8-loadtest`):** 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 `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/metrics/execution_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]
