Flink: Avoid per-row field getter allocation in RowDataWrapper#16789
Open
wombatu-kun wants to merge 1 commit into
Open
Flink: Avoid per-row field getter allocation in RowDataWrapper#16789wombatu-kun wants to merge 1 commit into
wombatu-kun wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RowDataWrapperadapts a FlinkRowDatato an IcebergStructLikeand sits on the hot path of every partitioned write (PartitionKey.partition), equality-delete key extraction, and range-shuffle sort-key computation. Its constructor pre-builds a getter for most types, butbuildGetterreturnsnullfor thedefaultcase, which covers the most common primitive types:INT,BIGINT,BOOLEAN,FLOAT,DOUBLE, andDATE. For those fields,get(pos, javaClass)falls back to constructing a fresh Flink field getter on every access:FlinkRowData.createFieldGetterallocates two lambdas per call (Flink'sRowData.createFieldGetterplus the null-checking wrapper around it), so every row that is partitioned, keyed, or shuffled on a primitive column allocates two short-lived objects for each such field.This pre-builds the fallback getter once in the constructor, the same way the wrapper already pre-builds getters for the handled types, so
getno longer allocates. Behavior is unchanged: the raw Flink value is already the correct Iceberg representation for every default-case type, which is exactly what the previous fallback returned.The change is identical across the supported Flink versions, so it is applied to v1.20, v2.0, and v2.1 in this PR.
Benchmark
JMH microbenchmark (JDK 17,
-prof gc) that wraps a row and reads its fields. The schema has seven columns;readPrimitiveKeyreads only the five primitive columns, representative of a typical partition or equality key.The remaining 75 B/op is return-value boxing that this change does not touch.
Existing
TestRowDataWrappercoverage passes unchanged.