-
Notifications
You must be signed in to change notification settings - Fork 506
[collections-722] deeply nested chainedIterator performance problems fixed #628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[collections-722] deeply nested chainedIterator performance problems fixed #628
Conversation
…pull/308 from collections-770, ensures that rechaining chainedIterators multiple times now result in a single IteratorChain instance with all picked up underlying iterators, thus avoiding deeply nested imperformant IteratorChain instances. Additionally the UnmodifiableIterator gets a special treatment, so that SetUtils.SetView.iterator() also benefits from this solution. Raised test coverage.
garydgregory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JoergBudi Please see my comment in UnmodifiableIterator. TY!
src/main/java/org/apache/commons/collections4/iterators/UnmodifiableIterator.java
Outdated
Show resolved
Hide resolved
…s-722-nested-chainedIterator switched to new UmodifiableIterator.unwrap()
|
@garydgregory : Is there something blocking the merging of this PR ? As solutions for other issues (see discussion in collections-838 / PR 630) might depend on it, it would be useful when it gets merged when it suits you. You might also discuss with @ppkarwasz . |
src/main/java/org/apache/commons/collections4/iterators/IteratorChain.java
Show resolved
Hide resolved
|
The recent #633 fixes the core problem of collections-722 as well. However the suggested changes in this PR still would save additional CPU cycles, but I am personally of the opinion, that added complexity and hard to understand code do not justify these small benefits. @ppkarwasz : What do you think ? Shall we still continue to pursue a change here ? If yes, I'd try your last suggestion via subclassing IteratorChain. But atm I favor dropping this PR and closing the jira issue 722 as duplicate to collections-838 |
|
Hi @JoergBudi, I think this PR is still worth pursuing, but we could narrow its scope to just collapsing For the unmodifiable part, I’ve experimented with the following approach:
This change would touch a lot of lines, so I plan to submit it separately. It would however enable collapsing nested iterators when they are interleaved with One open question: should The term “unmodifiable” is a bit misleading here: these iterators still maintain internal mutable state; the restriction applies only to the For What do you think? |
…s-722-nested-chainedIterator
|
@ppkarwasz : About IteratorChain and returning this (e.g. with a boolean marking remove() to throw an exception): While semantically that would work you would violate the marker interface contract (you can't dynamically add Unmodifiable to the instance so you either lie before or after calling toUnmodifiable()). So I think you continue to need similar unwrapping code knowing the possible classes one nesting level deeper, however it is difficult to think that through without actually trying it out. About this PR: I checked, that on a millisecond scale, the performance benefit of this PR is not really measurable up to a 1000 nestings. After that (5k nestings), the PR indeed avoids the StackOverflowError, but as no one has created a defect about that, I guess so deep nestings are uncommon. So have you got suggestions how to go on here ? Shall we merge the PR as is or have you got other improvements in mind beside the UnmodifiableConvertible I could add ? |
When I talked about returning
I think we should merge it as is. Can you add yourself to the |
|
added line changes.xml for this PR. |
Yes, |
basically 'renovated' stale PR #308 from collections-770, ensures that rechaining chainedIterators multiple times now result in a single IteratorChain instance with all picked up underlying iterators, thus avoiding deeply nested imperformant IteratorChain instances. Additionally the UnmodifiableIterator gets a special treatment, so that SetUtils.SetView.iterator() also benefits from this solution. Raised test coverage.
Note: From the comments in PR 308 (collections-770), I think, the PR stalled because it did not directly address the issue in that ticket, however there might be other reasons I am not aware of.
But as far as I can see, it fits perfectly for Collections-722. Cudos to original author stevebosman-oc.
Thanks for your contribution to Apache Commons! Your help is appreciated!
Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.