On Wed, 28 Aug 2024 09:28:59 GMT, Per Minborg <pminb...@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/ee29fdf0-a7cf-4d5b-bb6b-278b01d97e3c)
>> 
>> 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:
> 
>   Switch to bit checking instead of switch statement

Added some nit coments - overall, the code looks very clean, and it's nice to 
see this improvements... now onto copy :-)

test/micro/org/openjdk/bench/java/lang/foreign/TestFill.java line 87:

> 85:     public void buffer_fill() {
> 86:         // Hopefully, the creation of the intermediate array will be 
> optimized away.
> 87:         buffer.clear().put(new byte[ELEM_SIZE]);

I think this should use an "absolute" put with explicit offset, so that you can 
avoid the clear? Otherwise it's not apple to apple...

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

Marked as reviewed by mcimadamore (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/20712#pullrequestreview-2265840314
PR Review Comment: https://git.openjdk.org/jdk/pull/20712#discussion_r1734415133

Reply via email to