GH-3464 Improve DeltaByteArrayWriter.writeBytes to avoid unnecessary allocation and scalar prefix comparison#3465
Open
arouel wants to merge 2 commits intoapache:masterfrom
Open
GH-3464 Improve DeltaByteArrayWriter.writeBytes to avoid unnecessary allocation and scalar prefix comparison#3465arouel wants to merge 2 commits intoapache:masterfrom
DeltaByteArrayWriter.writeBytes to avoid unnecessary allocation and scalar prefix comparison#3465arouel wants to merge 2 commits intoapache:masterfrom
Conversation
…cessary allocation and scalar prefix comparison
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.
Rationale for this change
DeltaByteArrayWriter.writeBytes()is on the hot path forDELTA_BYTE_ARRAYencoding and had avoidable overhead:Per-value allocation from
getBytes().getBytes()always creates a new array. For prefix comparison this copy is unnecessary.Scalar prefix scan.
The byte-by-byte loop is replaced with
Arrays.mismatch(...), which maps to optimized JVM intrinsics.In profiling (custom JFR benchmark on a large merge workload), this method was a top allocation hotspot before the change.
What changes are included in this PR?
In
DeltaByteArrayWriter.writeBytes():v.getBytes()->v.getBytesUnsafe()for read-only prefix comparison.Arrays.mismatch(previous, 0, length, vb, 0, length).previous = vb->previous = v.isBackingBytesReused() ? v.getBytes() : vb(defensive copy only when the backing bytes may be reused by the caller).
This preserves semantics while removing unnecessary allocations in the common case.
Benchmark signal (custom, directional)
On a custom JFR-profiled merge workload (180M rows, 4 binary columns), this change significantly reduced allocations and lowered CPU attributed to this path.
(Results are workload/JDK dependent and provided as directional evidence.)
Are these changes tested?
Yes.
TestDeltaByteArrayround-trip tests (including skip/skipN/reset paths).testReusedBackingArrayRegressioninTestDeltaByteArrayto verify correctness when the same mutable backing array is reused across writes.Are there any user-facing changes?
No API or format changes. This is a transparent performance optimization; encoded data remains compatible/interchangeable.
Closes #3464