rishabhdaim opened a new pull request, #758: URL: https://github.com/apache/commons-collections/pull/758
`LazyIteratorChain.hasNext()` polls the active iterator twice. At 20 nested levels, one call reaches the leaf 1,048,576 times. COLLECTIONS-838 addressed the eager `IteratorChain` path. The lazy path used by `IterableUtils.chainedIterable()` and the iterator-of-iterators overload still reproduced the problem. Reuse the result within each `hasNext()` call. For nested Commons concatenation views, keep pending source positions and open only the leaf iterators. Track the active path by identity so cycles through a mutable varargs array raise an exception. A failed initial source lookup remains retryable. ### Tests - Count leaf polls separately for chained iterables and lazy chained iterators. Each now polls once at depth 20. - Traverse 100,000 appended singleton sources in order. The base overflows the stack. - Check that nested sources open on demand, each traversal opens its own iterator, and removal delegates to the opened source. - Insert a cycle through the varargs array, verify repeatable failure, then restore the source and resume. JMH 1.37 on Java 21, using the same harness on both revisions: | Workload | Base | Patch | | --- | ---: | ---: | | Flat, eight singleton sources | 27.0 ns/op | 28.1 ns/op | | One layer over 10,000 values | 28.3 µs/op | 24.2 µs/op | | Eight layers over 10,000 values | 19.98 ms/op | 43.5 µs/op | | 4,096 layers over 10,000 values | Not measured | 136.2 µs/op | Flat allocation was 192 B/op on both revisions. One-layer allocation went from 33 to 81 B/op. The benchmark profile now compiles Java sources only, so it skips the existing `overview.html`. Run it with `mvn test -Pbenchmark -Dbenchmark=ChainedIterableBenchmark`. The standard Maven build passed on Java 21 with 22,550 tests reported, zero failures or errors, and 82 skips. [COLLECTIONS-722](https://issues.apache.org/jira/browse/COLLECTIONS-722) · [COLLECTIONS-838](https://issues.apache.org/jira/browse/COLLECTIONS-838) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
