顺序拆分器上的 estimateSize()
estimateSize() on sequential Spliterator
我正在实施 Spliterator
,它通过 trySplit()
return null
明确限制并行化。实施 estimateSize()
是否会为此拆分器生成的流提供任何性能改进?或者估计大小仅对并行化有用?
编辑: 为澄清起见,我特意询问 估计 尺寸。换句话说,我的拆分器没有 SIZED
特性。
拆分器可以遍历元素:
1.Individually(tryAdvance())
2.Sequentially 散装(forEachRemaining())
As per java docs estimateSize()
在拆分时派上用场。
Spliterators can provide an estimate of the number of remaining
elements via the estimateSize() method. Ideally, as reflected in
characteristic SIZED, this value corresponds exactly to the number of
elements that would be encountered in a successful traversal. However,
even when not exactly known, an estimated value value may still be
useful to operations being performed on the source, such as helping to
determine whether it is preferable to split further or traverse the
remaining elements sequentially.
由于您的拆分器没有 SIZED 特性 estimateSize
将不会提供任何性能(因为没有并行性),但是请记住 Java-docs of estimateSize
不不提任何并行性,它只是说:
Returns: the estimated size, or Long.MAX_VALUE if infinite, unknown,
or too expensive to compute.
查看相关拆分器特征的调用层次结构表明它至少与 stream.toArray()
性能相关
此外,在内部流实现中有一个等效标志似乎用于排序:
所以除了并行流操作之外,大小估计似乎也用于这两个操作。
我的搜索并不详尽,因此仅以这些为例。
没有 SIZED 特性,我只能找到与流管道并行执行相关的 estimateSize()
调用。
当然,这可能会在未来发生变化,或者与标准 JDK 不同的 Stream 实现可能会有所不同。
我正在实施 Spliterator
,它通过 trySplit()
return null
明确限制并行化。实施 estimateSize()
是否会为此拆分器生成的流提供任何性能改进?或者估计大小仅对并行化有用?
编辑: 为澄清起见,我特意询问 估计 尺寸。换句话说,我的拆分器没有 SIZED
特性。
拆分器可以遍历元素:
1.Individually(tryAdvance())
2.Sequentially 散装(forEachRemaining())
As per java docs estimateSize()
在拆分时派上用场。
Spliterators can provide an estimate of the number of remaining elements via the estimateSize() method. Ideally, as reflected in characteristic SIZED, this value corresponds exactly to the number of elements that would be encountered in a successful traversal. However, even when not exactly known, an estimated value value may still be useful to operations being performed on the source, such as helping to determine whether it is preferable to split further or traverse the remaining elements sequentially.
由于您的拆分器没有 SIZED 特性 estimateSize
将不会提供任何性能(因为没有并行性),但是请记住 Java-docs of estimateSize
不不提任何并行性,它只是说:
Returns: the estimated size, or Long.MAX_VALUE if infinite, unknown, or too expensive to compute.
查看相关拆分器特征的调用层次结构表明它至少与 stream.toArray()
性能相关
此外,在内部流实现中有一个等效标志似乎用于排序:
所以除了并行流操作之外,大小估计似乎也用于这两个操作。
我的搜索并不详尽,因此仅以这些为例。
没有 SIZED 特性,我只能找到与流管道并行执行相关的 estimateSize()
调用。
当然,这可能会在未来发生变化,或者与标准 JDK 不同的 Stream 实现可能会有所不同。