Skip to content

Conversation

@hextriclosan
Copy link

@hextriclosan hextriclosan commented Oct 29, 2025

The manual byte-replication expression replaced with the multiplicative expansion trick - a more compact and efficient equivalent.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8370822: Improve performance for MemorySegment::fill (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28031/head:pull/28031
$ git checkout pull/28031

Update a local copy of the PR:
$ git checkout pull/28031
$ git pull https://git.openjdk.org/jdk.git pull/28031/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28031

View PR using the GUI difftool:
$ git pr show -t 28031

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28031.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 29, 2025

👋 Welcome back hextriclosan! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Oct 29, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Oct 29, 2025
@openjdk
Copy link

openjdk bot commented Oct 29, 2025

@hextriclosan The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 29, 2025
@hextriclosan
Copy link
Author

/solves JDK-8370822

@openjdk
Copy link

openjdk bot commented Oct 29, 2025

@hextriclosan This issue is referenced in the PR title - it will now be updated.

@mlbridge
Copy link

mlbridge bot commented Oct 29, 2025

Webrevs

@minborg
Copy link
Contributor

minborg commented Oct 31, 2025

I ran some benchmarks and was unable to see any significant performance improvements. I ran on Linux (a64/x64), macOS a64, and Windows x64. Can you provide benchmarks that support this is a performance improvement?

Benchmark Linux aarch64 Linux x64 MacOSX aarch64  Windows x64
openjdk.bench.java.lang.foreign.SegmentBulkFill.nativeSegmentFillJava-ELEM_SIZE:2 -0.05% -4.60% -0.12% -0.22%
openjdk.bench.java.lang.foreign.SegmentBulkFill.nativeSegmentFillJava-ELEM_SIZE:3 -0.01% -0.17% -1.18% 0.04%
openjdk.bench.java.lang.foreign.SegmentBulkFill.nativeSegmentFillJava-ELEM_SIZE:4 -0.01% 0.00% -0.01% 0.28%
openjdk.bench.java.lang.foreign.SegmentBulkFill.nativeSegmentFillJava-ELEM_SIZE:5 0.35% -0.00% 0.04% 0.18%
openjdk.bench.java.lang.foreign.SegmentBulkFill.nativeSegmentFillJava-ELEM_SIZE:512 -0.17% -0.84% 1.57% -0.05%
openjdk.bench.java.lang.foreign.SegmentBulkFill.nativeSegmentFillJava-ELEM_SIZE:6 0.00% 0.02% -0.01% 0.36%
openjdk.bench.java.lang.foreign.SegmentBulkFill.nativeSegmentFillJava-ELEM_SIZE:64 -0.03% -0.75% -5.88% -2.61%
openjdk.bench.java.lang.foreign.SegmentBulkFill.nativeSegmentFillJava-ELEM_SIZE:7 -0.11% -0.25% -0.02% 0.16%
openjdk.bench.java.lang.foreign.SegmentBulkFill.nativeSegmentFillJava-ELEM_SIZE:8 -0.01% -0.20% -0.07%  0.15%
@hextriclosan
Copy link
Author

I ran some benchmarks and was unable to see any significant performance improvements. I ran on Linux (a64/x64), macOS a64, and Windows x64. Can you provide benchmarks that support this is a performance improvement?

Hello Per-Ake,

I explored the corresponding code using JITWatch. My analysis shows that the patch reduces the number of instructions (in both bytecode and JIT-compiled assembly). However, as your benchmarks demonstrate, this does not lead to measurable overall performance improvement, the differences fall within normal noise.

So, the idea for the patch may be clarity and maintainability, as it simplifies and shortens the code.

Thanks.

@minborg
Copy link
Contributor

minborg commented Oct 31, 2025

Hello Per-Ake,

I explored the corresponding code using JITWatch. My analysis shows that the patch reduces the number of instructions (in both bytecode and JIT-compiled assembly). However, as your benchmarks demonstrate, this does not lead to measurable overall performance improvement, the differences fall within normal noise.

So, the idea for the patch may be clarity and maintainability, as it simplifies and shortens the code.

Thanks.

Interesting observation. I think reducing bytecode is also important. Are you able to share some JIT-compiled assembly before/after?

@hextriclosan
Copy link
Author

Here is syntactic example

Before
before

After
after

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review

2 participants