You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Ng Tsz Sum (Jira)" <ji...@apache.org> on 2022/04/29 16:23:00 UTC
[jira] [Comment Edited] (COLLECTIONS-722) IteratorUtils.chainedIterator() Performance Degrades
[ https://issues.apache.org/jira/browse/COLLECTIONS-722?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17530087#comment-17530087 ]
Ng Tsz Sum edited comment on COLLECTIONS-722 at 4/29/22 4:22 PM:
-----------------------------------------------------------------
Possible solutions:
Since the problem is due to deeply nested IteratorChain triggering huge amount of *hasNext()* call,
1. In IteratorChain.java, add a method *currentIteratorHasNext* method to replace all call to *currentIterator.hasNext()* and this method will act as a cache to reduce call to {*}currentIterator.hasNext(){*}, 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.
was (Author: samabcde):
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)