-
Notifications
You must be signed in to change notification settings - Fork 13k
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
[FLINK-12335][Table-runtime]Remove useless code in class SegmentsUtil #8278
Conversation
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community Review Progress
Please see the Pull Request Review Guide for a full explanation of the review process. The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commandsThe @flinkbot bot supports the following commands:
|
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.
Thanks @liyafan82 for you code, maybe you can change the title to remove useless code in SegmentsUtil
, I think the jdk/jvm will optimizer it, so maybe performance keep same.
@@ -445,7 +443,7 @@ public static void bitSet(MemorySegment segment, int baseOffset, int index) { | |||
* @param index bit index from base offset. | |||
*/ | |||
public static boolean bitGet(MemorySegment segment, int baseOffset, int index) { | |||
int offset = baseOffset + ((index & BIT_BYTE_POSITION_MASK) >>> 3); | |||
int offset = baseOffset + (index >>> 3); |
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.
Can you and a util method like this:
/**
* Given a bit index, return word index containing it.
*/
private static int wordIndex(int bitIndex) {
return bitIndex >> ADDRESS_BITS_PER_WORD;
}
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.
Good suggestion. Thank you.
@@ -417,7 +415,7 @@ private static boolean inFirstSegment(MemorySegment[] segments, int offset, int | |||
* @param index bit index from base offset. | |||
*/ | |||
public static void bitUnSet(MemorySegment segment, int baseOffset, int index) { | |||
int offset = baseOffset + ((index & BIT_BYTE_POSITION_MASK) >>> 3); | |||
int offset = baseOffset + (index >>> 3); | |||
byte current = segment.get(offset); | |||
current &= ~(1 << (index & BIT_BYTE_INDEX_MASK)); |
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.
It seems that BIT_BYTE_INDEX_MASK
is not needed either.
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.
Good point. Thanks for your comments.
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.
We can't remove BIT_BYTE_INDEX_MASK, the 1 <<
is int operation, but current &=
should be byte operation.
Thanks for your comments. I have made some investigations to analyze the assembly generated by JIT. |
Thanks @liyafan82 , LGTM +1 |
LGTM. |
1 similar comment
LGTM. |
Cool, thanks @liyafan82 for your contributions. |
…entsUtil
What is the purpose of the change
Improve the performance of SegmentsUtil class :
To evaluate the offset, an integer is bitand with a mask to clear to low bits, and then shift right. The bitand is useless:
((index & BIT_BYTE_POSITION_MASK) >>> 3)
Brief change log
Verifying this change
Verified by manually running existing test cases.
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: (no)Documentation