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

8264777: Overload optimized FileInputStream::readAllBytes #3845

Closed
wants to merge 9 commits into from

Conversation

bplb
Copy link
Member

@bplb bplb commented May 3, 2021

Please consider this request to override the java.io.InputStream methods readAllBytes() and readNBytes(int) in FileInputStream with more performant implementations. The method overrides attempt to read all requested bytes into a single array of the required size rather than composing the result from a sequence of smaller arrays. An example of the performance improvements is as follows.

readAllBytes
Before

Benchmark                                    (length)   Mode  Cnt      Score     Error  Units
ReadAllBytes.readAllBytesFileInputStream      1000000  thrpt   20   2412.031 ±   7.309  ops/s
ReadAllBytes.readAllBytesFileInputStream     10000000  thrpt   20    212.181 ±   0.369  ops/s
ReadAllBytes.readAllBytesFileInputStream    100000000  thrpt   20     19.860 ±   0.048  ops/s
ReadAllBytes.readAllBytesFileInputStream   1000000000  thrpt   20      1.298 ±   0.183  ops/s

After

Benchmark                                    (length)   Mode  Cnt      Score     Error  Units
ReadAllBytes.readAllBytesFileInputStream      1000000  thrpt   20   8218.473 ±  43.425  ops/s
ReadAllBytes.readAllBytesFileInputStream     10000000  thrpt   20    302.781 ±   1.273  ops/s
ReadAllBytes.readAllBytesFileInputStream    100000000  thrpt   20     22.461 ±   0.084  ops/s
ReadAllBytes.readAllBytesFileInputStream   1000000000  thrpt   20      1.502 ±   0.003  ops/s

readNBytes

N = file_size / 2

Before

Benchmark                                    (length)   Mode  Cnt      Score     Error  Units
ReadAllBytes.readHalfBytesFileInputStream     1000000  thrpt   20   5585.500 ± 153.353  ops/s
ReadAllBytes.readHalfBytesFileInputStream    10000000  thrpt   20    436.164 ±   1.104  ops/s
ReadAllBytes.readHalfBytesFileInputStream   100000000  thrpt   20     40.167 ±   0.141  ops/s
ReadAllBytes.readHalfBytesFileInputStream  1000000000  thrpt   20      3.291 ±   0.211  ops/s

After

Benchmark                                    (length)   Mode  Cnt      Score     Error  Units
ReadAllBytes.readHalfBytesFileInputStream     1000000  thrpt   20  15463.210 ±  66.045  ops/s
ReadAllBytes.readHalfBytesFileInputStream    10000000  thrpt   20    561.752 ±   0.951  ops/s
ReadAllBytes.readHalfBytesFileInputStream   100000000  thrpt   20     45.043 ±   0.102  ops/s
ReadAllBytes.readHalfBytesFileInputStream  1000000000  thrpt   20      4.629 ±   0.035  ops/s

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8264777: Overload optimized FileInputStream::readAllBytes

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3845/head:pull/3845
$ git checkout pull/3845

Update a local copy of the PR:
$ git checkout pull/3845
$ git pull https://git.openjdk.java.net/jdk pull/3845/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3845

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3845.diff

@bridgekeeper
Copy link

bridgekeeper bot commented May 3, 2021

👋 Welcome back bpb! 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 label May 3, 2021
@openjdk
Copy link

openjdk bot commented May 3, 2021

@bplb 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 label May 3, 2021
@mlbridge
Copy link

mlbridge bot commented May 3, 2021

@bplb
Copy link
Member Author

bplb commented May 7, 2021

All comments have been addressed. Are there any more? Thanks.

@bplb
Copy link
Member Author

bplb commented May 14, 2021

Any more comments on this? Thanks.

dfuch
dfuch approved these changes May 14, 2021
Copy link
Member

@dfuch dfuch left a comment

New changes look good to me.

@openjdk
Copy link

openjdk bot commented May 14, 2021

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

8264777: Overload optimized FileInputStream::readAllBytes

Reviewed-by: dfuchs, 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 220 new commits pushed to the master branch:

  • 79b3944: 8266520: Revert to OpenGL as the default 2D rendering pipeline for macOS
  • 3c010a7: 8265705: aarch64: KlassDecodeMovk mode broken
  • cf97252: 8264561: javap get NegativeArraySizeException on bad instruction
  • b8856b1: 8263614: javac allows local variables to be accessed from a static context
  • ea36836: 8267236: Versioned platform link in TestMemberSummary.java
  • d5a15f7: 8263438: Unused method AbstractMemberWriter.isInherited
  • dd5a84c: 8267162: Add jtreg test group definitions for langtools
  • 39a454b: 8260331: javax/swing/JInternalFrame/8146321/JInternalFrameIconTest.java failed with "ERROR: icon and imageIcon not same."
  • a29612e: 8255661: TestHeapDumpOnOutOfMemoryError fails with EOFException
  • a555fd8: 8264734: Some SA classes could use better hashCode() implementation
  • ... and 210 more: https://git.openjdk.java.net/jdk/compare/0544a732a44309bf7cbb44846dd9320c6096de17...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 label May 14, 2021
@AlanBateman
Copy link
Contributor

AlanBateman commented May 16, 2021

Any more comments on this? Thanks.

I think you've addressed the obvious bugs now but I'm still nervous that the lseek will fail for some special devices (time will tell).

It would be good to do some cleanup on the test before you integrate this. If you change it to use try-with-resources will it will avoid leaving the file open when the test fails. Also would be good to add a test for readNBytes(0) for the empty-file case. There's a typo in one of the exception messages ("expecte").

@bplb
Copy link
Member Author

bplb commented May 17, 2021

/integrate

@openjdk openjdk bot closed this May 17, 2021
@openjdk openjdk bot added the integrated label May 17, 2021
@openjdk openjdk bot removed ready rfr labels May 17, 2021
@openjdk
Copy link

openjdk bot commented May 17, 2021

@bplb Since your change was applied there have been 221 commits pushed to the master branch:

  • 3b11d81: 8266742: Check W^X state on possible safepoint
  • 79b3944: 8266520: Revert to OpenGL as the default 2D rendering pipeline for macOS
  • 3c010a7: 8265705: aarch64: KlassDecodeMovk mode broken
  • cf97252: 8264561: javap get NegativeArraySizeException on bad instruction
  • b8856b1: 8263614: javac allows local variables to be accessed from a static context
  • ea36836: 8267236: Versioned platform link in TestMemberSummary.java
  • d5a15f7: 8263438: Unused method AbstractMemberWriter.isInherited
  • dd5a84c: 8267162: Add jtreg test group definitions for langtools
  • 39a454b: 8260331: javax/swing/JInternalFrame/8146321/JInternalFrameIconTest.java failed with "ERROR: icon and imageIcon not same."
  • a29612e: 8255661: TestHeapDumpOnOutOfMemoryError fails with EOFException
  • ... and 211 more: https://git.openjdk.java.net/jdk/compare/0544a732a44309bf7cbb44846dd9320c6096de17...master

Your commit was automatically rebased without conflicts.

Pushed as commit da4dfde.

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

@bplb bplb deleted the FileInputStream-readNBytes-8264777 branch Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs integrated
6 participants