RFR: 8339531: Improve performance of MemorySegment::mismatch [v9]

Per Minborg pminborg at openjdk.org
Wed Sep 11 13:18:06 UTC 2024


On Fri, 6 Sep 2024 15:11:19 GMT, Brett Okken <duke at openjdk.org> wrote:

>> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Fix errors in a benchmark
>
> src/java.base/share/classes/jdk/internal/foreign/SegmentBulkOperations.java line 244:
> 
>> 242:         return (Architecture.isLittleEndian()
>> 243:                 ? Long.numberOfTrailingZeros(x)
>> 244:                 : Long.numberOfLeadingZeros(x)) / 8;
> 
> Would there be value in having a constant LongToIntFunction lambda to capture this logic?
> 
> 
> private static final LongToIntFunction LONG_LEADING_ZEROS = Architecture.isLittleEndian() ? Long::numberOfTrailingZeros : Long::numberOfLeadingZeros;

Performance-wise, I suspect there would not be that much of a difference. The compiler will see that Architecture.isLittleEndian provides a stable value and can optimize and eliminate code (I think). I am unsure which is easier to read.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20848#discussion_r1754496696


More information about the core-libs-dev mailing list