Skip to content

Conversation

@wenshao
Copy link
Contributor

@wenshao wenshao commented Jan 25, 2025

Since FloatToDecimal and DoubleToDecimal are used in Float.toString and Double.toString, some code in FloatingDecimal is not used.

This PR refactors FloatingDecimal and DigitList to improve efficiency and reduce code duplication.

Key changes:

  • Convert internal digit storage from char[] to byte[] for reduced memory footprint.
  • Remove unused code and methods that are no longer needed.

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-8365832: Optimize FloatingDecimal and DigitList with byte[] and cleanup (Enhancement - P4)

Reviewers

Reviewers without OpenJDK IDs

  • @zimmi (no known openjdk.org user name / role) Review applies to 1fe597d4

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23311

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@wenshao wenshao marked this pull request as draft January 25, 2025 13:05
@bridgekeeper
Copy link

bridgekeeper bot commented Jan 25, 2025

👋 Welcome back swen! 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 Jan 25, 2025

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

8365832: Optimize FloatingDecimal and DigitList with byte[] and cleanup

Reviewed-by: rgiulietti, liach

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

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
Copy link

openjdk bot commented Jan 25, 2025

@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.


}

private static final ThreadLocal<BinaryToASCIIBuffer> threadLocalBinaryToASCIIBuffer =
Copy link
Member

Choose a reason for hiding this comment

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

Why was this thread local buffer removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Creating a BinaryToASCIIConverter is not expensive and does not require the use of cache, but this should be proven by performance testing.

Copy link
Member

Choose a reason for hiding this comment

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

Each BinaryToASCIIBuffer allocates an array for digits. That might be why the buffer was added. @rgiulietti might decide if this removal is fine or if we should keep it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is interesting to note that that DigitList, which I think is the only remaining consumer of BinaryToAsciiBuffer reparses the string to separate the exponent and the mantissa. The converter has those separately and getChars does work to stick them together into a string. If the removal of the thread local has a noticeable performance impact, there is an opportunity to eliminate some allocations by having DigitList access the exponent and mantissa directly from the converter without needing toJavaFormatString

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 25, 2025

@wenshao This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 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!

@j3graham
Copy link
Contributor

j3graham commented May 2, 2025

@wenshao How about extracting a new PR from this that only deals with removing the unused code?

@wenshao
Copy link
Contributor Author

wenshao commented May 7, 2025

@wenshao How about extracting a new PR from this that only deals with removing the unused code?

Yes, but I will wait until after June 5th so that it does not affect the release of JDK 25.

@wenshao wenshao force-pushed the floating_dec_202501 branch from bfbe256 to 7e33814 Compare May 24, 2025 07:03
@rgiulietti
Copy link
Contributor

@wenshao I'm working on a general overhaul of FloatingDecimal and related classes in some current and future PRs.

If you could restrict your changes to just DigitList, that would be less interference with my work.

@wenshao
Copy link
Contributor Author

wenshao commented Jun 12, 2025

@wenshao I'm working on a general overhaul of FloatingDecimal and related classes in some current and future PRs.

If you could restrict your changes to just DigitList, that would be less interference with my work.

@rgiulietti Sorry, I was traveling last week and I just saw your comment now. This is a draft pull request, you can move on with your plans and ignore it.

@rgiulietti
Copy link
Contributor

@wenshao Curiously, there are now some people (you, @j3graham and myself) which are working on FloatingDecimal and related classes.

@wenshao
Copy link
Contributor Author

wenshao commented Jun 14, 2025

@wenshao Curiously, there are now some people (you, @j3graham and myself) which are working on FloatingDecimal and related classes.

In PR #23310, @j3graham 's comment on January 25 mentioned FloatingDecimal, so I paid attention to this class

@wenshao wenshao marked this pull request as ready for review August 2, 2025 10:04
@bridgekeeper
Copy link

bridgekeeper bot commented Aug 2, 2025

@wenshao 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 issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@wenshao
Copy link
Contributor Author

wenshao commented Aug 3, 2025

/touch

@openjdk
Copy link

openjdk bot commented Aug 3, 2025

@wenshao The pull request is being re-evaluated and the inactivity timeout has been reset.

@openjdk
Copy link

openjdk bot commented Aug 18, 2025

@wenshao this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout floating_dec_202501
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Aug 18, 2025
@wenshao wenshao marked this pull request as draft August 19, 2025 01:10
@wenshao wenshao force-pushed the floating_dec_202501 branch from 9803197 to ebc4bc2 Compare August 19, 2025 02:18
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Aug 19, 2025
@rgiulietti
Copy link
Contributor

@wenshao While I didn't check all the details, I think these changes look OK.

@wenshao wenshao changed the title Refactor FloatingDecimal 8365832: Refactor FloatingDecimal Aug 20, 2025
@wenshao wenshao marked this pull request as ready for review August 20, 2025 07:34
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 20, 2025
@rgiulietti
Copy link
Contributor

@wenshao In the initial description, there's a mention to reuse DecimalDigits to reduce code.
Is that still relevant? I'm asking because I don't see any usage of DecimalDigits.

@wenshao
Copy link
Contributor Author

wenshao commented Aug 20, 2025

@wenshao In the initial description, there's a mention to reuse DecimalDigits to reduce code. Is that still relevant? I'm asking because I don't see any usage of DecimalDigits.

Thanks @rgiulietti for the reminder, the original description is outdated and has been updated.

@rgiulietti
Copy link
Contributor

@wenshao There are several tests that fail, in particular in test/jdk/java/text/Format.
Please take a look.

Copy link

@zimmi zimmi left a comment

Choose a reason for hiding this comment

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

I'm not an official reviewer, but looks good to me 👍

P.S.: While looking why you might have preferred ISO_8859_1 over US_ASCII (latin1 can skip the mapping of replacement characters because it defines the entire byte range, correct?), I stumbled upon a reference to the removed SecurityManager in a comment.

@openjdk openjdk bot removed the rfr Pull request is ready for review label Aug 20, 2025
@liach
Copy link
Member

liach commented Aug 20, 2025

@zimmi, I created a simple issue for this outdated comment at https://bugs.openjdk.org/browse/JDK-8365887

@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 20, 2025
Copy link
Contributor

@rgiulietti rgiulietti 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.
Thanks @wenshao and the other participants.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 21, 2025
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Aug 21, 2025
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 21, 2025
@wenshao
Copy link
Contributor Author

wenshao commented Aug 22, 2025

/integrate

@liach
Copy link
Member

liach commented Aug 22, 2025

/touch

@openjdk
Copy link

openjdk bot commented Aug 22, 2025

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

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Aug 22, 2025

@wenshao Pushed as commit dba0d54.

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

@openjdk
Copy link

openjdk bot commented Aug 22, 2025

@liach The command touch can only be used in open pull requests.

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

Labels

core-libs [email protected] integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

5 participants