Repository navigation
Conversation
Java's Enum.values() clones a new array on every invocation, and PaneInfo.PaneInfoCoder.Encoding.fromTag previously called values() twice per decoded element. Cache Encoding.values() in a private static final array and reuse the computed index to eliminate per-element Encoding[] allocations during PaneInfoCoder.decode.
There was a problem hiding this comment.
📋 Review Summary
This PR optimizes PaneInfo.PaneInfoCoder.Encoding.fromTag(byte) by caching Encoding.values() in a static final array, avoiding two unnecessary array clone allocations per decoded element. It also expands PaneInfoTest to cover the ONE_INDEX encoding path for non-EARLY timings and tests invalid encoding tags.
🔍 General Feedback
- The changes are clean, well-scoped, and strictly preserve the existing behavior while eliminating hot-path allocations during
PaneInfodecoding.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @kennknowles for label java. 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). |
Avoid allocating a cloned
Encoding[]array twice per decoded element inPaneInfo.PaneInfoCoder.Encoding.fromTag(byte).Summary
Encoding.values()once in aprivate static final Encoding[] VALUESfield insidePaneInfo.PaneInfoCoder.Encoding.VALUESarray and computedindexinfromTag(byte).PaneInfoTestto coverEncoding.ONE_INDEXacross non-EARLYtimings and addtestDecodeInvalidEncodingThrowsCoderExceptionfor invalid encoding tag bytes.Testing
./gradlew :sdks:java:core:spotlessCheck :sdks:java:core:checkstyleMain :sdks:java:core:checkstyleTest :sdks:java:core:spotbugsMain :sdks:java:core:test --tests "org.apache.beam.sdk.transforms.windowing.PaneInfoTest" --tests "org.apache.beam.sdk.util.WindowedValueTest"