-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-9460] Avoid byte array allocation in StringPrefixComparator. #7765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,6 +137,15 @@ public int numChars() { | |
| return len; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a 64-bit integer that can be used as the prefix used in sorting. | ||
| */ | ||
| public long getPrefix() { | ||
| long p = PlatformDependent.UNSAFE.getLong(base, offset); | ||
| p = java.lang.Long.reverseBytes(p); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @tellison can you take a look at this (or find somebody else) to see if we can fix it by just not doing the reverse bytes in big-endian?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should check the numBytes here, or get random bytes if it's less than 8 bytes.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also test the endian-ness.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created https://github.com/apache/spark/pull/7789/files to make it safer. Still doesn't handle big endian though. |
||
| return p; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the underline bytes, will be a copy of it if it's part of another array. | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @JoshRosen
I made the randomized tester to be stricter. Previously it would still pass if prefix always return 0.