perf: use direct pointer reads in SparkUnsafeObject accessors#3658
Draft
andygrove wants to merge 3 commits intoapache:mainfrom
Draft
perf: use direct pointer reads in SparkUnsafeObject accessors#3658andygrove wants to merge 3 commits intoapache:mainfrom
andygrove wants to merge 3 commits intoapache:mainfrom
Conversation
Replace slice construction + try_into().unwrap() + from_le_bytes() with direct pointer dereferences in all SparkUnsafeObject trait accessors. Both SparkUnsafeRow and SparkUnsafeArray guarantee natural alignment for field access: UnsafeRow fields are at 8-byte aligned offsets (bitset width is multiple of 8, each slot is 8 bytes, JVM allocates aligned memory), and UnsafeArray elements are at naturally aligned offsets (header is 8-byte aligned, elements are at element_size stride). This eliminates three layers of abstraction per read (from_raw_parts, try_into().unwrap(), from_le_bytes) on the hottest path in row-to- columnar conversion.
SparkUnsafeArray elements may not be naturally aligned (e.g., i64 elements at 4-byte-aligned offsets). Use read_unaligned() instead of direct pointer dereferences for all multi-byte accessors. This is still faster than the original from_raw_parts + try_into + from_le_bytes chain while being safe for both SparkUnsafeRow (always aligned) and SparkUnsafeArray (potentially unaligned).
Contributor
|
Current code compiles down to a single load anyway |
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
from_raw_parts+try_into().unwrap()+from_le_bytes()with direct pointer dereferences (*(addr as *const T)) in allSparkUnsafeObjecttrait accessors (get_byte,get_short,get_int,get_long,get_float,get_double,get_date,get_timestamp)SparkUnsafeArray::newelement count readRationale
The previous
from_raw_parts+try_into().unwrap()+from_le_bytespattern added three layers of abstraction per read that compiled to unnecessary overhead. These accessors are on the hottest path in row-to-columnar conversion used by JVM shuffle.