Skip to content
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

JDK-8310502 : Optimization for j.l.Long.fastUUID() #14578

Closed
wants to merge 35 commits into from

Conversation

wenshao
Copy link
Contributor

@wenshao wenshao commented Jun 21, 2023

By optimizing the implementation of java.lang.Long#fastUUID, the performance of the java.util.UUID#toString method can be significantly improved.

The following are the test results of JMH:

Benchmark                     Mode  Cnt      Score      Error   Units
UUIDUtilsBenchmark.new       thrpt    5  92676.550 ±  292.213  ops/ms
UUIDUtilsBenchmark.original  thrpt    5  37040.165 ± 1023.532  ops/ms

Progress

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

Issue

  • JDK-8310502: Optimization for j.l.Long.fastUUID() (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14578

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 21, 2023

👋 Welcome back wenshao! 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 openjdk bot added the rfr Pull request is ready for review label Jun 21, 2023
@openjdk
Copy link

openjdk bot commented Jun 21, 2023

@wenshao 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 core-libs core-libs-dev@openjdk.org label Jun 21, 2023
@wenshao
Copy link
Contributor Author

wenshao commented Jun 21, 2023

git clone https://github.com/wenshao/jdk_8310502_test
cd jdk_8310502_test
mvn clean package -Dmaven.test.skip
java -cp target/jdk_8310502_benchmark.jar com.alibaba.openjdk.UUIDUtilsBenchmark
  • benchmark result on Apple MacBook M1 Max
Benchmark                 Mode  Cnt       Score       Error   Units
UUIDUtilsBenchmark.fast  thrpt    5  701840.078 ± 57597.624  ops/ms
UUIDUtilsBenchmark.jdk   thrpt    5  246409.000 ± 84564.009  ops/ms
Benchmark                 Mode  Cnt       Score      Error   Units
UUIDUtilsBenchmark.fast  thrpt    5  131595.572 ? 7383.223  ops/ms
UUIDUtilsBenchmark.jdk   thrpt    5  129610.735 ?  455.752  ops/ms
Benchmark                 Mode  Cnt       Score      Error   Units
UUIDUtilsBenchmark.fast  thrpt    5  129445.610 ? 1846.775  ops/ms
UUIDUtilsBenchmark.jdk   thrpt    5  104651.872 ? 1005.977  ops/ms

@openjdk
Copy link

openjdk bot commented Jun 22, 2023

@wenshao Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

@wenshao
Copy link
Contributor Author

wenshao commented Jun 22, 2023

@wenshao Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

got it

@RogerRiggs
Copy link
Contributor

fyi, the title of this PR need to match exactly the title of the bug JDK-8310502.
The mismatch is an Integration blocker. (See the comment in the description).

@wenshao wenshao changed the title 8310502 : optimization for UUID#toString JDK-8310502 : Optimization for j.l.Long.fastUUID() Jun 22, 2023
@wenshao
Copy link
Contributor Author

wenshao commented Jun 22, 2023

fyi, the title of this PR need to match exactly the title of the bug JDK-8310502. The mismatch is an Integration blocker. (See the comment in the description).

i have made the changes. is it ok now?

@RogerRiggs
Copy link
Contributor

The Bots have removed the warning so the titles match.
Please wait 24hrs to integrate to give anyone who has commented a chance to review and approve.

@liach
Copy link
Member

liach commented Jun 22, 2023

About @Glavo's VH suggestion: I think it is feasible, since the VH field is not initialized until the method is used, so there should be no startup issue.

On a side note, JDK itself has a UUIDBench that benchmarks toString as well: can run it with make test TEST="micro:java.util.UUIDBench.toString" once the configuration has JMH set up, which I will be using (against master and this patch)

@liach
Copy link
Member

liach commented Jun 22, 2023

I've tested the benchmarks and the patch and baseline (with extra stable annotation) with a slightly varied version suitable for gradle run:

package com.alibaba.openjdk;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Warmup(iterations = 3, time = 10)
@Measurement(iterations = 6, time = 5)
@Fork(1)
public class UUIDUtilsBenchmark {
    public static UUID uuid = UUID.randomUUID();

    @Benchmark
    public void jdk(Blackhole bh) {
        bh.consume(uuid.toString());
    }

    @Benchmark
    public void fast(Blackhole bh) {
        bh.consume(UUIDUtils.fastUUID(uuid));
    }
}

The throughput varies a lot between iterations somehow; the patch and baseline with stable has no significant difference (i.e. within the error range, about 10%)

@AlanBateman
Copy link
Contributor

/reviewers 2

@openjdk
Copy link

openjdk bot commented Jun 22, 2023

@AlanBateman
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you've got this to a good place with version 93e74b6. It might be helpful if the Digit.digts methods mentioned the endianness in the comment otherwise okay.

Copy link
Member

@liach liach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ByteArray can be safely used here: UUID is not used by anything in java.base and shouldn't be initialized on VM startup.

@openjdk
Copy link

openjdk bot commented Jun 29, 2023

⚠️ @wenshao the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout jdk_8310502_fast_uuid
$ git commit --author='Preferred Full Name <you@example.com>' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented Jun 29, 2023

@wenshao 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:

8310502: Optimization for j.l.Long.fastUUID()

Reviewed-by: liach, alanb

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 130 new commits pushed to the master branch:

  • 07734f6: 8310848: Convert ClassDesc and MethodTypeDesc to be stored in static final fields
  • e5744b8: 8310919: runtime/ErrorHandling/TestAbortVmOnException.java times out due to core dumps taking a long time on OSX
  • 98a954e: 8308286: Fix clang warnings in linux code
  • f842ec4: 8305667: Some fonts installed in user directory are not detected on Windows
  • 690d626: 8307927: C2: "malformed control flow" with irreducible loop
  • be64d3a: 8310299: C2: 8275201 broke constant folding of array store check in some cases
  • b2eae16: 8295191: IR framework timeout options expect ms instead of s
  • af319d9: 8311064: Windows builds fail without precompiled headers after JDK-8310728
  • cbf418a: 8311020: Typo cleanup in Classfile API
  • f4b900b: 8310902: (fc) FileChannel.transferXXX async close and interrupt issues
  • ... and 120 more: https://git.openjdk.org/jdk/compare/47d00a4cbeff5d757dda9c660dfd2385c02a57d7...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

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 (@AlanBateman) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 29, 2023
@wenshao
Copy link
Contributor Author

wenshao commented Jun 29, 2023

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jun 29, 2023
@openjdk
Copy link

openjdk bot commented Jun 29, 2023

@wenshao
Your change (at version 93e74b6) is now ready to be sponsored by a Committer.

@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Jun 29, 2023
@wenshao
Copy link
Contributor Author

wenshao commented Jun 29, 2023

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jun 29, 2023
@openjdk
Copy link

openjdk bot commented Jun 29, 2023

@wenshao
Your change (at version aea4e04) is now ready to be sponsored by a Committer.

@DamonFool
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Jun 29, 2023

Going to push as commit 20f7d05.
Since your change was applied there have been 130 commits pushed to the master branch:

  • 07734f6: 8310848: Convert ClassDesc and MethodTypeDesc to be stored in static final fields
  • e5744b8: 8310919: runtime/ErrorHandling/TestAbortVmOnException.java times out due to core dumps taking a long time on OSX
  • 98a954e: 8308286: Fix clang warnings in linux code
  • f842ec4: 8305667: Some fonts installed in user directory are not detected on Windows
  • 690d626: 8307927: C2: "malformed control flow" with irreducible loop
  • be64d3a: 8310299: C2: 8275201 broke constant folding of array store check in some cases
  • b2eae16: 8295191: IR framework timeout options expect ms instead of s
  • af319d9: 8311064: Windows builds fail without precompiled headers after JDK-8310728
  • cbf418a: 8311020: Typo cleanup in Classfile API
  • f4b900b: 8310902: (fc) FileChannel.transferXXX async close and interrupt issues
  • ... and 120 more: https://git.openjdk.org/jdk/compare/47d00a4cbeff5d757dda9c660dfd2385c02a57d7...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 29, 2023
@openjdk openjdk bot closed this Jun 29, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Jun 29, 2023
@openjdk
Copy link

openjdk bot commented Jun 29, 2023

@DamonFool @wenshao Pushed as commit 20f7d05.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@AlanBateman
Copy link
Contributor

@DamonFool In the future, please wait at least 24 hours before sponsoring changes like this. There have been 33 revisions of this change, many of the people that have commented, potential reviewers are in many time zones and need to have time to see a chance to look at changes before they are integrated.

/**
* Combine two hex shorts into one int based on big endian
*/
static int digit(int b0, int b1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name digit is not very informative.
As it is package private it should be more descriptive and describe the parameters and result.
Perhaps packDigits or encodeAndPackHexDigits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you create a new issue and i continue improving?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you create a new issue and i continue improving?

Filed: https://bugs.openjdk.org/browse/JDK-8311207

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liach @RogerRiggs continue discussion in PR 14745

@DamonFool
Copy link
Member

@DamonFool In the future, please wait at least 24 hours before sponsoring changes like this. There have been 33 revisions of this change, many of the people that have commented, potential reviewers are in many time zones and need to have time to see a chance to look at changes before they are integrated.

Okay, got it and will do so in the future.

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 integrated Pull request has been integrated