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

   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 `CompressionTypes` in `sdks/python/apache_beam/io/filesystem.py`:
   
   1. **Hoist `_VALID_TYPES`, `_MIME_TYPES`, and `_BY_SUFFIX` to class 
constants on `CompressionTypes` instead of rebuilding dictionaries and sets on 
every `is_valid_compression_type`, `mime_type`, and `detect_compression_type` 
call.**
   
   **Dataflow benchmarks showing improvement:**
   
   - Before the change: 
[`2026-11-12_12_17_56-4718277883720848495`](https://console.cloud.google.com/dataflow/jobs/us-central1/2026-11-12_12_17_56-4718277883720848495?project=apache-beam-testing)
   - After the change: 
[`2026-11-12_12_17_56-5944150860827631877`](https://console.cloud.google.com/dataflow/jobs/us-central1/2026-11-12_12_17_56-5944150860827631877?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 `25,000,000` text records · `WriteToText(GZIP)` → 
`ReadAllFromText(AUTO)` + `CompressionTypes` validation, built-in transform 
stage execution time improved from **`807,257 ms` -> `694,112 ms` (`1.16x` 
faster, `-14.0%`)** (total single-worker job vCPU time: `2163s` -> `2007s`).
   
   **Additional benchmarks**
   
   - **Strict Single-PR Isolated Microbenchmark (`upstream/master` vs 
`upstream/master` + this PR alone):** [`bench_47_compression_types_constants` 
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/microbenchmarks.py#L652-L659)
 (on branch 
[`perf/py-benchmarks-suite`](https://github.com/damccorm/beam/tree/perf/py-benchmarks-suite))
 — 500,000 iterations of `detect_compression_type("data.json.gz")`, 
`is_valid_compression_type("gzip")`, and `mime_type("gzip")` improved from 
**`538.65 ms` -> `196.68 ms` (`2.74x` faster, `-63.5%`, `-341.97 ms`)** in 
strict isolation.
   - **Per-Change Attribution (Most to Least Impact, 500,000 calls each in 
strict isolation):**
     1. *Most wall-time impact (`44.6%` of savings, `-144.30 ms`):* Hoisting 
`_BY_SUFFIX` in `CompressionTypes.detect_compression_type` — **`248.36 ms` -> 
`104.06 ms` (`2.39x` faster, `-58.1%`)**.
     2. *Second (`35.2%` of savings, `-113.86 ms`, highest relative speedup):* 
Hoisting `_VALID_TYPES` `frozenset` in 
`CompressionTypes.is_valid_compression_type` — **`154.22 ms` -> `40.36 ms` 
(`3.82x` faster, `-73.8%`)**.
     3. *Least impact (`20.2%` of savings, `-65.16 ms`):* Hoisting 
`_MIME_TYPES` in `CompressionTypes.mime_type` — **`118.46 ms` -> `53.30 ms` 
(`2.22x` faster, `-55.0%`)**.
   - **On-Worker Cloud Dataflow `n2-standard-4` Benchmark 
(`p28_ms:25_compression_types_500k`):** On a Cloud Dataflow `n2-standard-4` 
worker, 500,000 `CompressionTypes` calls improved from **`929 ms` -> `370 ms` 
(`2.51x` faster, `-60.2%`)**.
   - **End-to-End Cloud Dataflow Benchmark (`io_coders_transforms`):** Included 
in [`run_io_coders_transforms_pipeline` 
(`c2feb961eef`)](https://github.com/damccorm/beam/blob/c2feb961eef2e7d2410825aab9537c62a95e6790/sdks/python/apache_beam/testing/benchmarks/python_sdk_perf/dataflow_e2e_benchmarks.py#L305-L335)
 (3,000,000 records on `n2-standard-4`), which improved worker stage execution 
time by **1.48x (`-32.4%`, `49.2s` -> `33.3s`)**.
   
   ### Testing
   - Verified with `pytest sdks/python/apache_beam/io/filesystem_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