Integrated: 8246739: InputStream.skipNBytes could be implemented more efficiently

Brian Burkhalter bpb at openjdk.java.net
Tue Dec 1 20:10:57 UTC 2020


On Thu, 19 Nov 2020 19:29:43 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> Please review this modification of `java.io.InputStream.skipNBytes(long)` to improve its performance when `skip(long)` skips fewer than the requested number of bytes. In the current implementation, `skip(long)` is invoked once and, if not enough bytes have been skipped, then `read()` is invoked for each of the remaining bytes to be skipped. The proposed implementation instead repeatedly invokes `skip(long)` until the requested number of bytes has been skipped, or an error condition is encountered. For cases where `skip(long)` skips fewer bytes than the number requested, the new version was measured to be up to more than one thousand times faster than the old version. When `skip(long)` actually skips the requested number of bytes, the performance difference is insignificant.

This pull request has now been integrated.

Changeset: c5046ca5
Author:    Brian Burkhalter <bpb at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/c5046ca5
Stats:     20 lines in 1 file changed: 4 ins; 3 del; 13 mod

8246739: InputStream.skipNBytes could be implemented more efficiently

Reviewed-by: rriggs, lancea, naoto

-------------

PR: https://git.openjdk.java.net/jdk/pull/1329


More information about the core-libs-dev mailing list