RFR: 8338967: Improve performance for MemorySegment::fill [v3]

Per Minborg pminborg at openjdk.org
Mon Aug 26 12:11:30 UTC 2024


On Mon, 26 Aug 2024 11:59:44 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> The performance of the `MemorySegment::fil` can be improved by replacing the `checkAccess()` method call with calling `checkReadOnly()` instead (as the bounds of the segment itself do not need to be checked).
>> 
>> Also, smaller segments can be handled directly by Java code rather than transitioning to native code.
>> 
>> Here is how the `MemorySegment::fill` performance is improved by this PR:
>> 
>> ![image](https://github.com/user-attachments/assets/92a0bcf2-f5b0-4a91-9c02-39423f870209)
>> 
>> Operations involving 8 or more bytes are delegated to native code whereas smaller segments are handled via a switch rake.
>> 
>> It should be noted that `Arena::allocate` is using `MemorySegment::fil`. Hence, this PR will also have a positive effect on memory allocation performance.
>
> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Add a comment about the old switch type

Here is what it looks like for Windows x64:

![image](https://github.com/user-attachments/assets/53b6530c-76b7-47f1-ae02-124d16351d45)

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

PR Comment: https://git.openjdk.org/jdk/pull/20712#issuecomment-2310048420


More information about the core-libs-dev mailing list