Repository navigation
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR optimizes element metadata encoding and decoding across WindowedValues, ValueInSingleWindow, WindmillSink, UngroupedWindmillReader, and WindmillKeyedWorkItem by avoiding intermediate ElementMetadata builder allocations when metadata is at default values and decoding Windmill metadata in a single pass. The changes preserve wire compatibility and include unit test coverage for full and partial element metadata round-tripping.
🔍 General Feedback
- Single-pass decoding via
WindmillSink.decodeMetadataand zero-copy slicing viaByteString.substringcleanly eliminate redundantPaneInfoand window decoding passes when reading from Windmill. - Short-circuiting
hasNonDefaultElementMetadataand checkingpaneInfo.isElementMetadata()before the volatileisMetadataSupported()read reduce hot-path overhead when element metadata is unused.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #41739 +/- ##
============================================
- Coverage 59.59% 58.91% -0.68%
+ Complexity 5157 2342 -2815
============================================
Files 1470 1135 -335
Lines 187850 170674 -17176
Branches 3828 1530 -2298
============================================
- Hits 111942 100554 -11388
+ Misses 72503 67564 -4939
+ Partials 3405 2556 -849
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:
|
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
|
@kennknowles I think you know the most about element metadata. I'm trying to address extra overhead that runs per element (per-bundle overhead is ok, but per-element overhead is much more expensive and a scalability blocker). Metadata and also the OpenTelemetry contexts are per element, so trying to minimize that. |
Summary
Avoids allocating, serializing, and parsing
ElementMetadataproto payloads on the wire when all metadata fields have their wire defaults (CausedByDrain.NORMAL,ValueKind.INSERT, no non-root OpenTelemetryContext), and decodes Windmill message metadata in a single pass.Per
beam:coder:windowed_value:v2,metadata_lengthandmetadataare only present when the0x80bit is set on the first byte ofPaneInfo. Previously, enablingelement_metadata_supportedunconditionally set0x80and allocated/serialized/parsed anElementMetadataproto +byte[]on every element, even when all fields were defaults.Key Changes
FullWindowedValueCoder&ValueInSingleWindow.Coder(sdks/java/core):@Internal FullWindowedValueCoder.hasNonDefaultElementMetadata(...)and omit theElementMetadatapayload (clearing the0x80bit inPaneInfo) when all fields are wire defaults.drainwhenNORMAL,value_kindwhenINSERT) to shrink wire payloads.decode, check plainpaneInfo.isElementMetadata()before volatileisMetadataSupported(), and skipOpenTelemetryContextPropagator.read(...)whentraceparentandtracestateare empty.PaneInfo/PaneInfoCoder(sdks/java/core):PaneInfo.withElementMetadata(boolean)to returnthiswhen the flag is unchanged (eliminatesnew PaneInfo(...)allocation for internedFIRSTpanes on encode/decode).chooseEncoding(value)call inPaneInfoCoder.encode.WindmillSink,UngroupedWindmillReader, &WindmillKeyedWorkItem(runners/google-cloud-dataflow-java/worker):ElementMetadata.BuilderinWindmillSink.addwhen metadata is unsupported or all-default; omit default metadata bytes inWindmillSink.encodeMetadataand write non-default protos directly viametadata.writeTo(stream).PaneInfo, windows, optionalElementMetadata) in a singleInputStreampass instead of 3 separate passes.ElementMetadatavia zero-copyByteString.substring(...)instead ofparseFrom(InputStream)(which allocates a 4 KBCodedInputStreambuffer per call), and returnElementMetadata.getDefaultInstance()when unset.PaneInforeuse unit tests inWindowedValueTest,PaneInfoTest, andUngroupedWindmillReaderTest.Wire Compatibility
0x80set continue to decode cleanly in all updated decoders.isMetadataSupported() == false(0x80cleared), which existing decoders already handle by defaulting to(NORMAL, null/root, INSERT). Non-default elements omit default enum fields (DRAIN_MODE_UNSPECIFIED,VALUE_KIND_UNSPECIFIED), which existing decoders already map toNORMALandINSERT.Benchmark Results (JDK 21, 2 forks,
-prof gc,setMetadataSupported()ON)Wire Size (Default Element)
FullWindowedValueCoderValueInSingleWindow.CoderWindmillSinkmetadataLatency & Allocations (lower is better)
windmillKeyedWorkItem_decode_defaultfullWindowedValueCoder_decode_defaultvalueInSingleWindowCoder_encode_defaultvalueInSingleWindowCoder_decode_defaultfullWindowedValueCoder_encode_defaultwindmillSink_encodeMetadata_default*windmillKeyedWorkItem_decode_drain(non-default)fullWindowedValueCoder_encode_traced(non-default)*
WindmillSink.add()also skips allocatingElementMetadata.Builder+build()altogether before callingencodeMetadata.Verification
:sdks:java:core:spotlessCheck,checkstyleMain/Test,spotbugsMain, 18/18 tests (WindowedValueTest,PaneInfoTest,MetadataPropagationTest,ValueKindTest).:runners:google-cloud-dataflow-java:worker:spotlessCheck,checkstyleMain/Test, 26/26 tests (UngroupedWindmillReaderTest,WindmillKeyedWorkItemTest,WindmillSinkTest,StreamingGroupAlsoByWindowFnsTest,StreamingGroupAlsoByWindowsReshuffleDoFnTest,WindowingWindmillReaderTest).