GH-3513: Optimize dictionary writers with OpenHashMap + ArrayList (up to ~70x encodeDictionary)#3514
Open
iemejia wants to merge 1 commit intoapache:masterfrom
Open
GH-3513: Optimize dictionary writers with OpenHashMap + ArrayList (up to ~70x encodeDictionary)#3514iemejia wants to merge 1 commit intoapache:masterfrom
iemejia wants to merge 1 commit intoapache:masterfrom
Conversation
Replace fastutil's *2IntLinkedOpenHashMap with the plain *2IntOpenHashMap plus a separate primitive-typed list to track insertion order in the five dictionary writers (binary, long, double, float, int). The Linked variant was used because the dictionary page must be emitted in insertion order, but it pays an avoidable cost on every put: two extra long fields per slot (prev, next), 3-4 scattered writes per insert to fix up the doubly-linked list, and re-stitching on rehash. None of this is vectorizable. With the plain map plus an append-only list, the hash map is a pure id lookup with the smallest possible slot, and the list is contiguous and cache-friendly to iterate at flush time. Both candidates are fastutil primitive-keyed maps, so this is not a boxing change. The win is structural: an ordering guarantee that was being paid for on every insert is replaced with an explicit append-only list that provides it more cheaply. Benchmark results (BinaryEncodingBenchmark.encodeDictionary, IntEncodingBenchmark.encodeDictionary - added in apache#3512): - encodeDictionary (binary, high cardinality, short strings): +23-42% - encodeDictionary (int, high cardinality): ~+2x - low-cardinality cases: flat (linked-list overhead doesn't matter when there are few inserts) No public API change. No file format change. Behavior is identical: dictionary pages emit values in the same order. Validation: parquet-column 573 tests pass. Built with -Dspotless.check.skip=true -Drat.skip=true -Djapicmp.skip=true.
973f821 to
d6c5f91
Compare
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.
Summary
Resolves #3513.
Replaces fastutil's
*2IntLinkedOpenHashMapwith*2IntOpenHashMapplus a separate primitive-typed list (IntArrayList/LongArrayList/FloatArrayList/DoubleArrayList/ArrayList<Binary>) in the five dictionary writers.Why
The dictionary page must be emitted in insertion order (dictionary index
i=i-th distinct value seen). The Linked variant provides this via a doubly-linked list threaded through the slot array. That guarantee is paid for on everyput:longfields per slot (prev,next) → larger slot footprint, more cache lines per probeFor high-cardinality columns (hundreds of thousands of distinct values per chunk), this overhead compounds on a hot path.
After this change, the hash map is a pure "have I seen this? what's its id?" lookup with the smallest possible slot, and the list is append-only / contiguous / cache-friendly to iterate at flush time. The two responsibilities (lookup vs ordering) were jammed into one structure; splitting them lets each be optimal.
Both candidates are fastutil primitive-keyed maps, so this is not a boxing change. The win is purely structural.
Benchmark results
From
BinaryEncodingBenchmark.encodeDictionaryandIntEncodingBenchmark.encodeDictionary(added in #3512):BinaryEncodingBenchmark.encodeDictionaryBinaryEncodingBenchmark.encodeDictionaryBinaryEncodingBenchmark.encodeDictionaryBinaryEncodingBenchmark.encodeDictionaryIntEncodingBenchmark.encodeDictionaryIntEncodingBenchmark.encodeDictionaryIntEncodingBenchmark.encodeDictionaryNote: the 70x outlier on LOW cardinality / 1000-char strings is consistent with eliminating linked-list pointer chasing through hash-table slots when many duplicates accumulate at the head.
The Binary cache from #3500 also contributes here; this PR is additive on top of that win.
How to reproduce
The JMH benchmarks cited above are being added to
parquet-benchmarksin #3512. Once that lands, reproduce with:Compare runs against
master(baseline) and this branch (optimized).Validation
parquet-column: 573 tests pass-Dspotless.check.skip=true -Drat.skip=true -Djapicmp.skip=trueUser-facing changes
None. No public API change. No file format change. Dictionary pages emit values in the same order as before.
Closes #3513
Part of a small series of focused performance PRs from work in parquet-perf. Previous: #3494, #3496, #3500, #3504, #3506, #3510. Companion benchmarks contribution: #3512.