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

8315454: Add a way to create an immutable snapshot of a BitSet #15530

Closed
wants to merge 8 commits into from

Conversation

minborg
Copy link
Contributor

@minborg minborg commented Sep 1, 2023

This PR proposes adding a new method to BitSet that provides an immutable snapshot of the set in the form of an IntPredicate.

The predicate is eligible for constant folding.

Here are some classes in the JDK that would benefit directly from constant-folding of BitSets:

PoolReader (6)
URLEncoder (1) - Updated in this PR
HtmlTree (2)

More over, the implementation of the predicate is @valuebased and this would provide additional benefits in the future.

Initial benchmarks with the URLEncoder show encouraging results:

Name                           (encodeChars) (maxLength) (unchanged) Cnt  Base   Error   Test   Error  Unit  Diff%
URLEncodeDecode.testEncodeUTF8             6        1024           0  15 2,371 ± 0,016  2,073 ± 0,184 ms/op  12,6% (p = 0,000*)
URLEncodeDecode.testEncodeUTF8             6        1024          75  15 1,772 ± 0,013  1,387 ± 0,032 ms/op  21,8% (p = 0,000*)
URLEncodeDecode.testEncodeUTF8             6        1024         100  15 1,230 ± 0,009  1,140 ± 0,011 ms/op   7,3% (p = 0,000*)

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-8315454: Add a way to create an immutable snapshot of a BitSet (Enhancement - P4)

Reviewers

Contributors

  • Claes Redestad <redestad@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15530

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

Using diff file

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

Webrev

Link to Webrev Comment

@minborg
Copy link
Contributor Author

minborg commented Sep 1, 2023

/csr

@minborg
Copy link
Contributor Author

minborg commented Sep 1, 2023

/contributor add redestad

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 1, 2023

👋 Welcome back pminborg! 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 rfr Pull request is ready for review csr Pull request needs approved CSR before integration labels Sep 1, 2023
@openjdk
Copy link

openjdk bot commented Sep 1, 2023

@minborg has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@minborg please create a CSR request for issue JDK-8315454 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

@openjdk
Copy link

openjdk bot commented Sep 1, 2023

@minborg
Contributor Claes Redestad <redestad@openjdk.org> successfully added.

@openjdk
Copy link

openjdk bot commented Sep 1, 2023

@minborg The following labels will be automatically applied to this pull request:

  • core-libs
  • net

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

@openjdk openjdk bot added core-libs core-libs-dev@openjdk.org net net-dev@openjdk.org labels Sep 1, 2023
@mlbridge
Copy link

mlbridge bot commented Sep 1, 2023

Webrevs

@liach
Copy link
Member

liach commented Sep 1, 2023

What about the missing functionalities, such as ranged get, cardinality, next/previousSet/ClearBit?

@SirYwell
Copy link
Member

SirYwell commented Sep 1, 2023

Maybe it would make sense to start with a JDK-internal variant before exploring potential public API?

@minborg
Copy link
Contributor Author

minborg commented Sep 1, 2023

What about the missing functionalities, such as ranged get, cardinality, next/previousSet/ClearBit?

This was explored in #15493

@minborg
Copy link
Contributor Author

minborg commented Sep 1, 2023

Maybe it would make sense to start with a JDK-internal variant before exploring potential public API?

This is certainly one alternative.

@mcimadamore
Copy link
Contributor

Maybe it would make sense to start with a JDK-internal variant before exploring potential public API?

This is certainly one alternative.

When looking at this I thought about that too. It seems like the particular case where this optimization is applicable is very specific, and I'm on the fence as to whether this deserves a public API. At the same time, there might be near-misses that could be difficult to address once the API is set in stone. I'd suggest to let it bake (inside the JDK) for some time, and later on decide whether it should be exposed as a public API.

All that said, the idea of exposing a fast predicate over an immutable snapshot is very cute and clever :-)

@cl4es
Copy link
Member

cl4es commented Sep 1, 2023

While I think this minimal API could well prove to be a useful addition to many projects, this was conceived on a whim and while it's sufficient for URLEncoder and a few internal users, there's no evidence that this API fits the needs of third-party code. I'd be happy with an internal implementation initially.

@minborg
Copy link
Contributor Author

minborg commented Sep 1, 2023

/csr unneeded

@openjdk
Copy link

openjdk bot commented Sep 1, 2023

@minborg only Reviewers can determine that a CSR is not needed.

@cl4es
Copy link
Member

cl4es commented Sep 1, 2023

/csr unneeded

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Sep 1, 2023
@openjdk
Copy link

openjdk bot commented Sep 1, 2023

@cl4es determined that a CSR request is not needed for this pull request.

@minborg minborg changed the title 8315454: Add an immutable BitSet 8315454: Add a way to create an immutable snapshot of a BitSet Sep 1, 2023
@mlbridge
Copy link

mlbridge bot commented Sep 2, 2023

Mailing list message from John Rose on core-libs-dev:

On 1 Sep 2023, at 2:38, Maurizio Cimadamore wrote:

On Fri, 1 Sep 2023 09:07:34 GMT, Per Minborg <pminborg at openjdk.org> wrote:

Maybe it would make sense to start with a JDK-internal variant before exploring potential public API?

This is certainly one alternative.

When looking at this I thought about that too. It seems like the particular case where this optimization is applicable is very specific, and I'm on the fence as to whether this deserves a public API. At the same time, there might be near-misses that could be difficult to address once the API is set in stone. I'd suggest to let it bake (inside the JDK) for some time, and later on decide whether it should be exposed as a public API.

All that said, the idea of exposing a fast predicate over an immutable snapshot is very cute and clever :-)

There is a related API I call Classifier which takes a List<T> l and returns an immutable IntFunction<T>, where the function works like x->l.indexOf(x). The reason it might deserve (someday) to be its own API is that the factory for a classifier might be allowed to do significant work to create an optimized instruction sequence for classifying its inputs. The literature of perfect hash functions would apply in many cases, and the classifier spun up for some particular list might operate in O(1) time. The reason I started thinking about such things was considering the optimization of switches (say, over strings or other values) and the optimization of RE character classes. Perfect hashing applies in both cases, but the heuristic algorithms should be hidden behind an API, and Classifier is what came up for me as the centerpiece. (That plus classifier factories on various kinds of lists and arrays and other sequences or sets.)

? John

Copy link
Member

@cl4es cl4es left a comment

Choose a reason for hiding this comment

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

Looks good to me. Since we're not adding any public API I think it's ok to include the URLEncoder changes so that we can use that benchmark as a proxy for verifying BitSet::asPredicate performance.

@openjdk
Copy link

openjdk bot commented Sep 4, 2023

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

8315454: Add a way to create an immutable snapshot of a BitSet

Co-authored-by: Claes Redestad <redestad@openjdk.org>
Reviewed-by: redestad

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

  • 6c821f5: 8315545: C1: x86 cmove can use short branches
  • d7e4087: 8315369: [JVMCI] failure to attach to a libgraal isolate during shutdown should not be fatal
  • d1cabe4: 8315566: [JVMCI] deadlock in JVMCI startup when bad option specified
  • 94a74a0: 8315534: Incorrect warnings about implicit annotation processing
  • 84425a6: 8315452: Erroneous AST missing modifiers for partial input
  • 3094fd1: 8314662: jshell shows duplicated signatures of javap
  • 0d52c82: 8310220: IGV: dump graph after each IGVN step at level 4
  • adfc1d6: 8313323: javac -g on a java file which uses unnamed variable leads to ClassFormatError when launching that class
  • 2dc930d: 8314997: Missing optimization opportunities due to missing try_clean_mem_phi() calls
  • ab12c5d: 8315549: CITime misreports code/total nmethod sizes
  • ... and 15 more: https://git.openjdk.org/jdk/compare/764f65c8b442697dfd46ee7a4c97971b28eb887b...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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 4, 2023
@minborg
Copy link
Contributor Author

minborg commented Sep 5, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Sep 5, 2023

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

  • 9def453: 8314580: PhaseIdealLoop::transform_long_range_checks fails with assert "was tested before"
  • 6c821f5: 8315545: C1: x86 cmove can use short branches
  • d7e4087: 8315369: [JVMCI] failure to attach to a libgraal isolate during shutdown should not be fatal
  • d1cabe4: 8315566: [JVMCI] deadlock in JVMCI startup when bad option specified
  • 94a74a0: 8315534: Incorrect warnings about implicit annotation processing
  • 84425a6: 8315452: Erroneous AST missing modifiers for partial input
  • 3094fd1: 8314662: jshell shows duplicated signatures of javap
  • 0d52c82: 8310220: IGV: dump graph after each IGVN step at level 4
  • adfc1d6: 8313323: javac -g on a java file which uses unnamed variable leads to ClassFormatError when launching that class
  • 2dc930d: 8314997: Missing optimization opportunities due to missing try_clean_mem_phi() calls
  • ... and 16 more: https://git.openjdk.org/jdk/compare/764f65c8b442697dfd46ee7a4c97971b28eb887b...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Sep 5, 2023

@minborg Pushed as commit f292268.

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

@cl4es cl4es mentioned this pull request Sep 5, 2023
3 tasks
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 net net-dev@openjdk.org
6 participants