On Tue, 12 Apr 2022 18:00:18 GMT, XenoAmess <d...@openjdk.java.net> wrote:

>> Is this change proposed as the result of some experience with particular 
>> apps and streams or just observation of the implementation?
>> 
>> Is there any information about what kind of underlying streams do not 
>> support skip directly
>> and what is the distribution of sizes expected to be 'skipped'?
>> GIven the object instance overhead of an array, I'd be inclined to suggest a 
>> minimum size that would
>> cover all of the 'small' skipping that could occur. And if that's not big 
>> enough, jump to the MAX_SKIP_BUFFER_SIZE. To keep the code simple, I'd start 
>> at 128bytes and jump to the max if that's not big enough.  There is precious 
>> little actual information available to fine tune.
>
>> Is this change proposed as the result of some experience with particular 
>> apps and streams or just observation of the implementation?
> 
> just observation of the implementation of InputStream class and Reader class, 
> and somehow wonder why there be different handling in skip to these 2 classes.
> 
>> Is there any information about what kind of underlying streams do not 
>> support skip directly and what is the distribution of sizes expected to be 
>> 'skipped'? GIven the object instance overhead of an array, I'd be inclined 
>> to suggest a minimum size that would cover all of the 'small' skipping that 
>> could occur. And if that's not big enough, jump to the MAX_SKIP_BUFFER_SIZE. 
>> To keep the code simple, I'd start at 128bytes and jump to the max if that's 
>> not big enough. There is precious little actual information available to 
>> fine tune.
> 
> It whould make the problem @liach said above heavier.
> 
> For example, if people just invoke 129, then the imput stream object hold a 
> 8192 length array until it die.
> 
> That sounds much too memory wasting.

Without specific information about use cases, there isn't enough information to
craft a good algorithm/solution and simplicity is preferred. 
The MAX_SKIP_BUFFER_SIZE is 2048 (not 8192).

What subclasses of InputStream in the JDK do not override skip(n)?
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.

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.

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

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

Reply via email to