RFR: 8284638: store skip buffers in InputStream Object [v2]

liach duke at openjdk.java.net
Tue Apr 12 23:38:39 UTC 2022


On Tue, 12 Apr 2022 22:15:22 GMT, XenoAmess <duke at openjdk.java.net> wrote:

> What subclasses of InputStream in the JDK do not override skip(n)?

>From a peek, the majority of subclasses do not override `skip(long)`. Most overrides are delegations or optimizations for random access structures; but there are some that create their custom local variable skip buffers, usually of size 512 or minimum of 512 and the skip size. These custom skip buffer ones IMO should have their overrides removed.

> Most sequential streams are open for a relatively short period of time, the lifetime of the
> memory for the buffer won't change the memory usage enough to notice.

True, and with good use of try-with-resources, these instance fields' array allocations shouldn't be too much of a problem compared to allocation in every skip(long) call.

> If the concern is about tying up memory then allocate the buffer once and
don't resize it. Each resize consumes extra memory and gc cycles to reclaim the last buffer.
> Use the requested size but at least nnn and at most MAX_SKIP_BUFFER_SIZE.

Shouldn't be too problematic, as most skip usages in JDK as I see are skipping small number of bytes like 2 or 4, or like skipping over attributes of Java class files. A minimum skip buffer size isn't that helpful, as I don't think we often see skip calls with slowly incremental sizes.

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

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


More information about the core-libs-dev mailing list