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

8344668: Unnecessary array allocations and copying in TextLine #22288

Closed
wants to merge 3 commits into from

Conversation

gredler
Copy link
Contributor

@gredler gredler commented Nov 21, 2024

When LineBreakMeasurer is used to break text into lines, internally it uses TextMeasurer and TextLine to do the job. In the common case, TextLine.getComponents(...) allocates a TextLineComponent[] with room for a single array entry, and passes it to TextLine.createComponentsOnRun(...), which fills the array and returns it, optionally resizing to a larger array if necessary, after which the array is resized back down to actual size (if necessary).

Unfortunately TextLine.createComponentsOnRun(...) is too eager in allocating larger arrays. In the most common case of a single component, this means that a single-element array is allocated, then a 9-element array is allocated (via expandArray(...)), and then another single-element array is allocated (to shrink the array back to actual size). Only one array allocation is necessary in this common case, and no array copying is 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-8344668: Unnecessary array allocations and copying in TextLine (Bug - P5)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22288

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 21, 2024

👋 Welcome back dgredler! 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 Nov 21, 2024

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

8344668: Unnecessary array allocations and copying in TextLine

Reviewed-by: honkar, azvegint, prr

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

  • 874d68a: 8343747: C2: TestReplicateAtConv.java crashes with -XX:MaxVectorSize=8
  • d9a2213: 8345299: C2: some nodes can still have incorrect control after do_range_check()
  • 2286fae: 8345159: RISCV: Fix -Wzero-as-null-pointer-constant warning in emit_static_call_stub
  • 8403285: 8268145: [macos] Rendering artifacts is seen when text inside the JTable with TableCellEditor having JTextfield
  • aa38284: 8345435: Eliminate tier1_compiler_not_xcomp group
  • 9284602: 8345628: [BACKOUT] JDK-8287122 Use gcc12 -ftrivial-auto-var-init=pattern in debug builds
  • 41c8971: 8287122: Use gcc12 -ftrivial-auto-var-init=pattern in debug builds
  • 5da0eee: 8285692: Enable _FORTIFY_SOURCE=2 when building with Clang
  • daa2ba5: 8339622: Regression in make open-hotspot-xcode-project
  • 6f6bce5: 8344559: Log is spammed by missing pandoc warnings when building man pages
  • ... and 599 more: https://git.openjdk.org/jdk/compare/84c99fb91ffc4bfbc2fb0f20f558603d5660d7f1...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 (@prrace, @honkar-jdk, @azvegint) 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 rfr Pull request is ready for review label Nov 21, 2024
@openjdk
Copy link

openjdk bot commented Nov 21, 2024

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

  • client

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 client client-libs-dev@openjdk.org label Nov 21, 2024
@mlbridge
Copy link

mlbridge bot commented Nov 21, 2024

Webrevs

Copy link
Contributor

@prrace prrace left a comment

Choose a reason for hiding this comment

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

I see. This is very wasteful.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 23, 2024
@gredler
Copy link
Contributor Author

gredler commented Nov 29, 2024

@mrserb Would you have a few free cycles to provide the second review for this PR?

@prrace
Copy link
Contributor

prrace commented Dec 4, 2024

@azvegint @TejeshR13 @prsadhuk @honkar-jdk - this needs a 2nd reviewer

Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

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

@gredler There is one other place where expandArray() is called similarly - TextLine.getComponents().

@gredler
Copy link
Contributor Author

gredler commented Dec 5, 2024

@honkar-jdk Good catch -- I've gone ahead and fixed that one, too.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Dec 5, 2024
Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

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

LGTM. Ran awt/font and java/awt/font/LineBreakMeasurer tests with fix and they work as expected.

@gredler Missed mentioning it earlier, copyright year needs to be updated for TextLine.java

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 5, 2024
@gredler
Copy link
Contributor Author

gredler commented Dec 5, 2024

@honkar-jdk Done! Let me know if there's anything else that catches your eye.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Dec 5, 2024
Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

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

@honkar-jdk Done! Let me know if there's anything else that catches your eye.

Looks good now. Re-approved.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 5, 2024
@gredler
Copy link
Contributor Author

gredler commented Dec 5, 2024

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Dec 5, 2024
@openjdk
Copy link

openjdk bot commented Dec 5, 2024

@gredler
Your change (at version 557a3b1) is now ready to be sponsored by a Committer.

@gredler
Copy link
Contributor Author

gredler commented Dec 5, 2024

@prrace I think this is ready to be sponsored. Thanks!

@azvegint
Copy link
Member

azvegint commented Dec 6, 2024

/sponsor

@openjdk
Copy link

openjdk bot commented Dec 6, 2024

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

  • 874d68a: 8343747: C2: TestReplicateAtConv.java crashes with -XX:MaxVectorSize=8
  • d9a2213: 8345299: C2: some nodes can still have incorrect control after do_range_check()
  • 2286fae: 8345159: RISCV: Fix -Wzero-as-null-pointer-constant warning in emit_static_call_stub
  • 8403285: 8268145: [macos] Rendering artifacts is seen when text inside the JTable with TableCellEditor having JTextfield
  • aa38284: 8345435: Eliminate tier1_compiler_not_xcomp group
  • 9284602: 8345628: [BACKOUT] JDK-8287122 Use gcc12 -ftrivial-auto-var-init=pattern in debug builds
  • 41c8971: 8287122: Use gcc12 -ftrivial-auto-var-init=pattern in debug builds
  • 5da0eee: 8285692: Enable _FORTIFY_SOURCE=2 when building with Clang
  • daa2ba5: 8339622: Regression in make open-hotspot-xcode-project
  • 6f6bce5: 8344559: Log is spammed by missing pandoc warnings when building man pages
  • ... and 599 more: https://git.openjdk.org/jdk/compare/84c99fb91ffc4bfbc2fb0f20f558603d5660d7f1...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 6, 2024
@openjdk openjdk bot closed this Dec 6, 2024
@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 Dec 6, 2024
@openjdk
Copy link

openjdk bot commented Dec 6, 2024

@azvegint @gredler Pushed as commit f6021a9.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants