-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8284493: Improve computeNextExponential tail performance and accuracy #8131
Conversation
Hi @Pr0methean, welcome to this OpenJDK project and thanks for contributing! We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user Pr0methean" as summary for the issue. If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing |
@Pr0methean The following label will be automatically applied to this pull request:
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. |
/covered |
/covered |
Thank you! Please allow for a few business days to verify that your employer has signed the OCA. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated! |
hi, @JesperIRL, |
Should we extract a computeWinsorizedNextExponential that can compute a smaller value for line 1216 to compare the output to, so that line 1218 can realistically be covered in a unit test? Such a method might even be worth exposing in the RandomGenerator interface, in case an approximately exponential distribution is ever needed in a hard real-time system. |
/covered @robilad, can you please verify Chris Hennick's (@Pr0methean) OCA status? |
Webrevs
|
src/java.base/share/classes/jdk/internal/util/random/RandomSupport.java
Outdated
Show resolved
Hide resolved
In addition to the changes discussed heretofore, I've also changed line 1382 to eliminate unneeded tail exploration; this should make |
@Pr0methean Please do not rebase or force-push to an active PR as it invalidates existing review comments. All changes will be squashed into a single commit automatically when integrating. See OpenJDK Developers’ Guide for more information. |
@Pr0methean Please do not rebase or force-push to an active PR as it invalidates existing review comments. All changes will be squashed into a single commit automatically when integrating. See OpenJDK Developers’ Guide for more information. |
@Pr0methean Please do not rebase or force-push to an active PR as it invalidates existing review comments. All changes will be squashed into a single commit automatically when integrating. See OpenJDK Developers’ Guide for more information. |
@Pr0methean Please do not rebase or force-push to an active PR as it invalidates existing review comments. All changes will be squashed into a single commit automatically when integrating. See OpenJDK Developers’ Guide for more information. |
@Pr0methean This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
I have now reviewed all the changes in file .../jdk/internal/util/random/RandomSupport.java . It appears that the method formerly called computeWinsorizedNextExponential has been renamed to computeNextExponentialSoftCapped, and that is a good change. All the changes to the executable code appear to be sound (and, yes, I believe I still remember how all this code is supposed to work—even while admitting that I wrote it some years ago and that a couple of embarrassing mistakes were later discovered and repaired, thank goodness). I looked especially carefully at the change of representation for the variable "extra" from double to long and the new uses of fma. I went back and looked at email exchanges I had with Joe Darcy on May 10, 2022, and I see that many of the concerns I expressed at that time have been addressed. I do suggest that for extra clarity, the declaration and computation of maxExtraMinus1 at lines 1206--1212 be moved down below to after line 1222, just below the comment that begins "We didn't use the upper part of U1 after all". It may be that good optimizing Java compilers perform this code motion anyway (the code in lines 1213–1221 does not refer to maxExtraMinus1), but it would help a human reader to understand that this code is not part of and does not need to be part of the fast path through the code. Moreover, though a compiler cannot tell that it's okay to move the comparison of maxValue to 0.0 (and the possible forced return of 0.0) off the fast path, I argue that it is indeed okay to do so, because it is always permitted to return a value larger than maxValue, and the fast path does always return a nonnegative value. So I actually argue to move three more lines (in all, lines 1203–1212) to after line 1222. In all other respects, I recommend that this set of changes be adopted exactly as is. If making the one change I suggested above might cause adoption to slip from JDK21 to JDK22 (perhaps because of a need for retesting), then I would suggest adopting the code exactly as is and then scheduling the suggested change for JDK22, because the suggested change improves clarity and code speed but should not change the advertised functionality at all. |
Moved the code after the fast-path return as requested. |
|
Latest change looks good. I noted the improvement to the comment beginning "We didn't use the upper part of U1 after all". |
@Pr0methean This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@turbanoff @rgiulietti Keep open |
@JimLaskey @jddarcy I believe this can now be merged. |
@Pr0methean This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@JimLaskey @jddarcy @turbanoff @rgiulietti Could this please be merged? |
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.
As Guy is not a capital-R reviewer for this project, marking the PR as Approved on his behalf.
@Pr0methean This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been no new commits pushed to the As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@jddarcy) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
@Pr0methean , please update your branch with the current contents of the master before issuing the integrate command. Assuming that succeeds as expected, myself or someone else can sponsor your changeset as described in the comment from the Skara bots. |
/integrate |
@jddarcy Done. |
@Pr0methean |
/sponsor |
Going to push as commit f975be4. |
@jddarcy @Pr0methean Pushed as commit f975be4. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This PR improves both the worst-case performance of
nextExponential
andnextGaussian
and the distribution of output at the tails. It fixes the following imperfections:2*exponentialX0 == 0x1.e46eff20739afp3 ~ 15.1
); this PR fixes that by tracking the multiple of exponentialX0 as a long. (This distortion is worst whenx > 0x1.0p56
since in that case, a rounding error meansextra + x == extra
.Math.fma
. (This will almost certainly improve performance, and may or may not improve output distribution.)computeWinsorizedNextExponential
function to preventnextGaussian
from going into thenextExponential
tail twice.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/8131/head:pull/8131
$ git checkout pull/8131
Update a local copy of the PR:
$ git checkout pull/8131
$ git pull https://git.openjdk.org/jdk.git pull/8131/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 8131
View PR using the GUI difftool:
$ git pr show -t 8131
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/8131.diff
Webrev
Link to Webrev Comment