Flink: Avoid per-row allocations in Parquet array and map writers#16791
Open
wombatu-kun wants to merge 1 commit into
Open
Flink: Avoid per-row allocations in Parquet array and map writers#16791wombatu-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.
FlinkParquetWriters'ArrayDataWriterandMapDataWriterallocate per row when writing array and map columns. For every value,elements(...)/pairs(...)create a fresh iterator, whose constructor in turn callsArrayData.createElementGetter(...)for the element (and both key and value for maps). For nullable element/value typescreateElementGetterreturns a capturing null-checking wrapper, so it allocates too; the map iterator additionally allocates aReusableEntryper row.The element/key/value getters depend only on the column types, which are fixed at writer construction, so they are now built once in the writer. The iterators themselves are reused: the parent
RepeatedWriter/RepeatedKeyValueWriterfully consumes the iterator inside a singlewrite()call and never retains it (it drains it in awhileloop), and writers are single-threaded, so one reusable iterator instance per writer (reset on each call, with the map'sReusableEntryallocated once) is safe. Nested collections use distinct writer instances, so no iterator is ever re-entered.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 (JDK 17,
-prof gc, SingleShotTime), end-to-end Flink Parquet write of 1,000,000 rows ofid: long, tags: array<int>, props: map<string, long>, measured for non-nullable and nullable (optional) element/value types.(Allocation per 1,000,000-row write.) Wall-clock time was unchanged within noise; this is an allocation / GC-pressure reduction on collection-heavy writes. Existing
TestFlinkParquetWriter/TestFlinkParquetReaderround-trip coverage (arrays, maps, nested structs, required and optional, dictionary and fallback encodings) passes unchanged.