[
https://issues.apache.org/jira/browse/COLLECTIONS-722?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17530087#comment-17530087
]
Ng Tsz Sum commented on COLLECTIONS-722:
----------------------------------------
Possible solutions:
1. In IteratorChain.java, add a method *currentIteratorHasNext* method to
replace all call to *currentIterator.next()* and this method will act as a
cache to reduce call to {*}currentIterator.next(){*}, of course we need to
clear the cache whenever *currentIterator* next/remove is called or is pointing
to something else. Drawback is the code are less readable.
2. Update the document in *IteratorUtils.chainedIterator(iterator1, iterator2)*
to warn user not to use this method inside a for loop to chain IteratorChain.
which will create deeply nested object and result in bad performance. Suggest
them to use
*chainedIterator(final Iterator<? extends E>... iterators)*
or
*chainedIterator(final Collection<Iterator<? extends E>> iterators)*
instead.
> IteratorUtils.chainedIterator() Performance Degrades
> ----------------------------------------------------
>
> Key: COLLECTIONS-722
> URL: https://issues.apache.org/jira/browse/COLLECTIONS-722
> Project: Commons Collections
> Issue Type: Bug
> Affects Versions: 4.1
> Reporter: E P
> Priority: Major
> Attachments: IteratorUtilsTest.java
>
>
> IteratorUtils.chainedIterator() performance degrades when chaining iterators
> with chained iterators. The slowdown appears to be exponential, based upon
> the number of chains created. The attached test shows the issue.
> As a reference, the same test below works as expected using Google's Guava
> Iterator.concat() functionality. It is possible I am misusing the API, but
> the javadoc did not indicate as much.
>
--
This message was sent by Atlassian Jira
(v8.20.7#820007)