Repository navigation
Conversation
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR introduces a Cython-friendly fast path in AbstractComponentCoderImpl for 2-component (KV) tuples by caching _coder_0, _coder_1, _num_coders, and _is_kv at initialization time. The optimization is clean, preserves existing wire format and nesting semantics, and yields substantial throughput gains for KV encoding/decoding.
🔍 General Feedback
- In
decode_from_stream, the non-KV fallback path replaced thec-bound loop variable withself._coder_impls[i].decode_from_stream(...), which loses theCoderImplstatic Cython type ontupleindexing and falls back to Python attribute lookup. coder_impl.pxddeclareslast=intin@cython.localsforget_estimated_size_and_observables, wherelastis not defined.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR adds a fast path for 2-component (KV) coders in AbstractComponentCoderImpl.encode_to_stream and AbstractComponentCoderImpl.decode_from_stream, along with corresponding Cython attribute and local variable declarations in coder_impl.pxd. The implementation preserves exact nested encoding/decoding semantics and component length validation while eliminating loop and list-allocation overhead on the hot path.
🔍 General Feedback
- The 2-component unrolling accurately preserves the
nested=Truebehavior for the first component and forwardsnestedto the second component. - Passing a 2-tuple directly to
_construct_from_componentsindecode_from_streamcleanly takes advantage ofTupleCoderImpl._construct_from_components(tuple(components)) returning the existing tuple without extra allocation. - Cython
cdefattributes and@cython.localsdeclarations incoder_impl.pxdare properly aligned with the implementation incoder_impl.py.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41216 +/- ##
============================================
+ Coverage 57.48% 57.82% +0.34%
Complexity 2492 2492
============================================
Files 1204 1200 -4
Lines 171265 171969 +704
Branches 2103 2103
============================================
+ Hits 98456 99446 +990
+ Misses 70157 69871 -286
Partials 2652 2652
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR introduces a fast path in AbstractComponentCoderImpl for 2-component (KV) tuples by caching Cython-typed attributes (_num_coders, _is_kv, _coder_0, _coder_1) and unrolling encode_to_stream and decode_from_stream. All previous review comments regarding Cython local typing have been properly addressed, and the implementation is clean and behaviorally identical to the general N-ary path.
🔍 General Feedback
- The fast path accurately preserves component nesting semantics (
Truefor the first component,nestedfor the second) and component length validation (self._num_coders != len(values)). - Cython declarations in
coder_impl.pxdproperly match the implementation incoder_impl.py, maintaining typedcpdefdispatch for both the 2-component fast path and the fallback loop.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @shunping for label python. This pull request likely touches a core component ("core" label). Please review with scrutiny. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
;tldr - AbstractComponentCoderImpl is most commonly used for KVs, so we should make that specific path faster.
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:
Full details of the methodology of generation and review can be found here - Apache Beam Python SDK Performance PRs Methodology & Branches Impact Ranking
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
AbstractComponentCoderImplinsdks/python/apache_beam/coders/coder_impl.pyandsdks/python/apache_beam/coders/coder_impl.pxd:KV) fast path inencode_to_streamanddecode_from_stream:_num_coders,_is_kv,_coder_0, and_coder_1whenlen(self._coder_impls) == 2so 2-tuples (KVpairs) encode and decode directly withoutrange()loop overhead or list comprehension +tuple()allocation on every element.Dataflow benchmarks showing improvement:
2026-11-12_12_17_27-132005701317629638742026-11-12_12_17_26-14979577080798624478n1-standard-8,--autoscaling_algorithm=NONE --num_workers=1 --max_num_workers=1) Cloud Dataflow pipeline running50,000,000typedKV[int, tuple[int, int]]·CombinePerKey(CountCombineFn), built-in transform stage execution time improved from613,960 ms->539,217 ms(1.14xfaster,-12.2%) (total single-worker job vCPU time:1860s->1729s).Additional benchmarks
Isolated Microbenchmark Rerun (
upstream/mastervsupstream/master+ this PR alone):bench_17_component_coder_kv_fastpath(c2feb961eef) (on branchperf/py-benchmarks-suite) — 500,000 2-tuple (KV) encode + decode round-trips inTupleCoderImplimproved from220.40 ms->124.94 ms(1.76xfaster,-43.3%,-95.46 ms) in compiled Cython.Per-Change Attribution (Most to Least Impact, 500,000 calls each in compiled Cython):
60.7%of stream savings,-38.66 ms): 2-componentencode_to_streamfast path (_coder_0.encode_to_stream/_coder_1.encode_to_stream) —74.72 ms->36.06 ms(2.07xfaster,-51.7%).39.3%of stream savings,-25.06 ms): 2-componentdecode_from_streamfast path ((_coder_0.decode_from_stream, _coder_1.decode_from_stream)without list comprehension +tuple()) —62.73 ms->37.67 ms(1.67xfaster,-39.9%).End-to-End Cloud Dataflow Benchmark (
core_window_row_combine): Included inrun_core_window_row_combine_pipeline(c2feb961eef) (3,000,000 generated events -> 9,000,000 sliding-windowed elements on a singlen2-standard-4worker), 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->838vCPU-s).Per-Piece Ablation Breakdown (Compiled Cython,
465.38 ms->280.70 ms,1.66xfaster,-184.69 msacross 400k 2-tuple KV + 100k 3-tuple round-trips):KVfast path inAbstractComponentCoderImpl.encode_to_stream55.4%(-102.40 ms)6.0%(-11.08 ms, overlaps with typed loop)KVfast path inAbstractComponentCoderImpl.decode_from_stream29.4%(-54.28 ms)14.7%(-27.18 ms)cdef int _num_coders+ typedi, lastloop bounds forN-ary tuples15.2%(-28.01 ms)15.8%(-29.22 ms)Testing
pytest sdks/python/apache_beam/coders/coders_test.py sdks/python/apache_beam/coders/fast_coders_test.py.