RFR: 8264777: Overload optimized FileInputStream::readAllBytes
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 ------------- Commit messages: - 8264777: Overload optimized FileInputStream::readAllBytes Changes: https://git.openjdk.java.net/jdk/pull/3845/files Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=00 Issue: https://bugs.openjdk.java.net/browse/JDK-8264777 Stats: 221 lines in 4 files changed: 215 ins; 1 del; 5 mod Patch: https://git.openjdk.java.net/jdk/pull/3845.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/3845/head:pull/3845 PR: https://git.openjdk.java.net/jdk/pull/3845
On Mon, 3 May 2021 20:33:23 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
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
src/java.base/share/classes/java/io/FileInputStream.java line 342:
340: 341: private native long length() throws IOException; 342: private native long position() throws IOException;
Can you confirm that you've tested with special files? It's very likely that there will be cases where lseek will fail. ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
On Tue, 4 May 2021 14:07:18 GMT, Alan Bateman <alanb@openjdk.org> wrote:
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
src/java.base/share/classes/java/io/FileInputStream.java line 342:
340: 341: private native long length() throws IOException; 342: private native long position() throws IOException;
Can you confirm that you've tested with special files? It's very likely that there will be cases where lseek will fail.
Only regular files this far. Are there any particular special files which would be of interest? ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
On Tue, 4 May 2021 17:46:15 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
src/java.base/share/classes/java/io/FileInputStream.java line 342:
340: 341: private native long length() throws IOException; 342: private native long position() throws IOException;
Can you confirm that you've tested with special files? It's very likely that there will be cases where lseek will fail.
Only regular files this far. Are there any particular special files which would be of interest?
On `/proc/cpuinfo` for example, `fstat()` succeeds but `st_size` in `struct stat` is zero. The correct position is however returned by `lseek()`. Apparently this proposal needs to be reworked to expect size zero when the size is in fact non-zero. ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
On Tue, 4 May 2021 19:01:45 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
Only regular files this far. Are there any particular special files which would be of interest?
On `/proc/cpuinfo` for example, `fstat()` succeeds but `st_size` in `struct stat` is zero. The correct position is however returned by `lseek()`. Apparently this proposal needs to be reworked to expect size zero when the size is in fact non-zero.
Updated to handle `length() == 0` case. Not sure however whether for this case it might not be better just to fall back to `super.readXBytes()` instead. ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
On Tue, 4 May 2021 20:13:20 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
On `/proc/cpuinfo` for example, `fstat()` succeeds but `st_size` in `struct stat` is zero. The correct position is however returned by `lseek()`. Apparently this proposal needs to be reworked to expect size zero when the size is in fact non-zero.
Updated to handle `length() == 0` case. Not sure however whether for this case it might not be better just to fall back to `super.readXBytes()` instead.
Can you rename the native length and position methods to length0 and position0 as we will need to wrap these methods later. Also it will keep them consistent with RAF. ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision: 8264777: Handle cases where length() returns zero ------------- Changes: - all: https://git.openjdk.java.net/jdk/pull/3845/files - new: https://git.openjdk.java.net/jdk/pull/3845/files/8b568686..98a03a55 Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=01 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=00-01 Stats: 25 lines in 1 file changed: 16 ins; 2 del; 7 mod Patch: https://git.openjdk.java.net/jdk/pull/3845.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/3845/head:pull/3845 PR: https://git.openjdk.java.net/jdk/pull/3845
On Tue, 4 May 2021 20:18:25 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
8264777: Handle cases where length() returns zero
src/java.base/share/classes/java/io/FileInputStream.java line 284:
282: long size = length - position; 283: if (size > (long)Integer.MAX_VALUE) 284: throw new OutOfMemoryError("Required array size too large");
What do you think of adding "length, position, and size" to the exception message? ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
On Wed, 5 May 2021 06:50:17 GMT, Vladimir Sitnikov <vsitnikov@openjdk.org> wrote:
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
8264777: Handle cases where length() returns zero
src/java.base/share/classes/java/io/FileInputStream.java line 284:
282: long size = length - position; 283: if (size > (long)Integer.MAX_VALUE) 284: throw new OutOfMemoryError("Required array size too large");
What do you think of adding "length, position, and size" to the exception message?
We usually don't do that for OutOfMemoryError because concatenation implies allocation ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
On Wed, 5 May 2021 11:00:21 GMT, Rémi Forax <github.com+828220+forax@openjdk.org> wrote:
src/java.base/share/classes/java/io/FileInputStream.java line 284:
282: long size = length - position; 283: if (size > (long)Integer.MAX_VALUE) 284: throw new OutOfMemoryError("Required array size too large");
What do you think of adding "length, position, and size" to the exception message?
We usually don't do that for OutOfMemoryError because concatenation implies allocation
Well, here `OutOfMemory` is more like "I can't read all the data since the array won't fit". It would definitely help to have actual file size there, especially in case filesystem returns weird values (e.g. negative file length). This branch will almost never be taken, and even if taken, it won't be "low memory" condition. So the allocation does not hurt, however, it would simplify the analysis should the case trigger. ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
On Wed, 5 May 2021 13:20:13 GMT, Vladimir Sitnikov <vsitnikov@openjdk.org> wrote:
We usually don't do that for OutOfMemoryError because concatenation implies allocation
Well, here `OutOfMemory` is more like "I can't read all the data since the array won't fit". It would definitely help to have actual file size there, especially in case filesystem returns weird values (e.g. negative file length).
This branch will almost never be taken, and even if taken, it won't be "low memory" condition. So the allocation does not hurt, however, it would simplify the analysis should the case trigger.
What about adding the filename into exception message? ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision: 8264777: Change length == 0 case to fall back to superclass method; add dimensions to OutOfMemoryError message ------------- Changes: - all: https://git.openjdk.java.net/jdk/pull/3845/files - new: https://git.openjdk.java.net/jdk/pull/3845/files/98a03a55..bfc5598b Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=02 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=01-02 Stats: 29 lines in 1 file changed: 8 ins; 11 del; 10 mod Patch: https://git.openjdk.java.net/jdk/pull/3845.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/3845/head:pull/3845 PR: https://git.openjdk.java.net/jdk/pull/3845
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision: 8264777: Fix typo in error message ------------- Changes: - all: https://git.openjdk.java.net/jdk/pull/3845/files - new: https://git.openjdk.java.net/jdk/pull/3845/files/bfc5598b..5a4d9114 Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=03 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=02-03 Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod Patch: https://git.openjdk.java.net/jdk/pull/3845.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/3845/head:pull/3845 PR: https://git.openjdk.java.net/jdk/pull/3845
On Wed, 5 May 2021 17:10:13 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
8264777: Fix typo in error message
src/java.base/share/classes/java/io/FileInputStream.java line 289:
287: } 288: if (size <= 0L) 289: return new byte[0];
Maybe the case where size <= 0L should also default to `return super.readAllBytes()`? ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
On Wed, 5 May 2021 17:18:08 GMT, Daniel Fuchs <dfuchs@openjdk.org> wrote:
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
8264777: Fix typo in error message
src/java.base/share/classes/java/io/FileInputStream.java line 289:
287: } 288: if (size <= 0L) 289: return new byte[0];
Maybe the case where size <= 0L should also default to `return super.readAllBytes()`?
Yes, that might be better. ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision: 8264777: Improve handling of position, length, and size checks ------------- Changes: - all: https://git.openjdk.java.net/jdk/pull/3845/files - new: https://git.openjdk.java.net/jdk/pull/3845/files/5a4d9114..0e476822 Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=04 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=03-04 Stats: 16 lines in 1 file changed: 5 ins; 4 del; 7 mod Patch: https://git.openjdk.java.net/jdk/pull/3845.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/3845/head:pull/3845 PR: https://git.openjdk.java.net/jdk/pull/3845
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision: 8264777: Make length and position consistent with RAF; add path to OOME message ------------- Changes: - all: https://git.openjdk.java.net/jdk/pull/3845/files - new: https://git.openjdk.java.net/jdk/pull/3845/files/0e476822..5272d5ef Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=05 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=04-05 Stats: 13 lines in 2 files changed: 7 ins; 0 del; 6 mod Patch: https://git.openjdk.java.net/jdk/pull/3845.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/3845/head:pull/3845 PR: https://git.openjdk.java.net/jdk/pull/3845
On Thu, 6 May 2021 16:40:31 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
8264777: Make length and position consistent with RAF; add path to OOME message
All comments have been addressed. Are there any more? Thanks. ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
On Thu, 6 May 2021 16:40:31 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
8264777: Make length and position consistent with RAF; add path to OOME message
src/java.base/share/classes/java/io/FileInputStream.java line 319:
317: } 318: 319: public byte[] readNBytes(int len) throws IOException {
readNBytes(0) is specified to return an empty array, it looks like this implementation will throw IIOBE. Can you check this? ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision: 8264777: Handle readNBytes(0): src/test ------------- Changes: - all: https://git.openjdk.java.net/jdk/pull/3845/files - new: https://git.openjdk.java.net/jdk/pull/3845/files/5272d5ef..4fae0209 Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=06 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=05-06 Stats: 6 lines in 2 files changed: 5 ins; 0 del; 1 mod Patch: https://git.openjdk.java.net/jdk/pull/3845.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/3845/head:pull/3845 PR: https://git.openjdk.java.net/jdk/pull/3845
On Mon, 10 May 2021 17:54:52 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
8264777: Handle readNBytes(0): src/test
Any more comments on this? Thanks. ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
On Fri, 14 May 2021 15:57:48 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
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"). ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
On Mon, 10 May 2021 17:54:52 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
8264777: Handle readNBytes(0): src/test
New changes look good to me. ------------- Marked as reviewed by dfuchs (Reviewer). PR: https://git.openjdk.java.net/jdk/pull/3845
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision: 8264777: Clean up test ------------- Changes: - all: https://git.openjdk.java.net/jdk/pull/3845/files - new: https://git.openjdk.java.net/jdk/pull/3845/files/4fae0209..17e21c9a Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=07 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=06-07 Stats: 49 lines in 1 file changed: 6 ins; 3 del; 40 mod Patch: https://git.openjdk.java.net/jdk/pull/3845.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/3845/head:pull/3845 PR: https://git.openjdk.java.net/jdk/pull/3845
On Mon, 17 May 2021 17:00:15 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
8264777: Clean up test
Marked as reviewed by alanb (Reviewer). test/jdk/java/io/FileInputStream/ReadXBytes.java line 69:
67: 68: try (FileInputStream fis = new FileInputStream(empty)) { 69: byte[] b = fis.readAllBytes();
You could move this readAllBytes test up to the previous block if you want. ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision: 8264777: Merge two try-with-resources blocks in test ------------- Changes: - all: https://git.openjdk.java.net/jdk/pull/3845/files - new: https://git.openjdk.java.net/jdk/pull/3845/files/17e21c9a..76895a0c Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=08 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=3845&range=07-08 Stats: 7 lines in 1 file changed: 0 ins; 4 del; 3 mod Patch: https://git.openjdk.java.net/jdk/pull/3845.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/3845/head:pull/3845 PR: https://git.openjdk.java.net/jdk/pull/3845
On Mon, 17 May 2021 17:53:05 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
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
Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
8264777: Merge two try-with-resources blocks in test
Marked as reviewed by alanb (Reviewer). ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
On Mon, 3 May 2021 20:33:23 GMT, Brian Burkhalter <bpb@openjdk.org> wrote:
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
This pull request has now been integrated. Changeset: da4dfde7 Author: Brian Burkhalter <bpb@openjdk.org> URL: https://git.openjdk.java.net/jdk/commit/da4dfde71a176d2b8401782178e854d4c924... Stats: 244 lines in 4 files changed: 238 ins; 1 del; 5 mod 8264777: Overload optimized FileInputStream::readAllBytes Reviewed-by: dfuchs, alanb ------------- PR: https://git.openjdk.java.net/jdk/pull/3845
participants (6)
-
Alan Bateman
-
Brian Burkhalter
-
Daniel Fuchs
-
Rémi Forax
-
Vladimir Sitnikov
-
Сергей Цыпанов